#python-discussion

1 messages Β· Page 583 of 1

turbid sigil
#

πŸ‘‹

clear crystal
#

im actually new to programming. im learning flask rn

gleaming knoll
#

how so?

velvet holly
gleaming knoll
#

the intention is already written, 0.0 is known to be a float

velvet holly
#

Its like having auto everywhere in C++ to me

grave tree
#

Is var = 0.0 not clear about the intention?

clear crystal
#

i have no idea what are you talking about

turbid sigil
#

we do type hinting for parameters to functions.

velvet holly
gleaming knoll
#

0.0 is a python float (double)

grave tree
bronze dragon
velvet holly
#

I'm specifically passing it to functions that could differ with f32/f64 though. Thats why I'm typing it to make it obvious what the intended type is

turbid sigil
# clear crystal i have no idea what are you talking about

if you've worked in java or C before, data types have to be explicitly declared, like:

int number = 4

Python automatically assumes its type int, because that's the closest to the number type:

number = 4

dyssyn2 is confused that we don't declare the type for the variable.

velvet holly
harsh anchor
turbid sigil
#

^ that too

grave tree
clear crystal
turbid sigil
#

they can change on the fly

gleaming knoll
clear crystal
#

it makes sense tho

velvet holly
turbid sigil
clear crystal
harsh anchor
#

what about them

velvet holly
#

the best C++ practice is to use explicit types when the deduced type isn't immediately obvious from auto (or if the explicit type is very unreadable)

grave tree
cerulean ravine
bronze dragon
brittle merlin
#

what was your dumbest DUMBEST college/ school project idea?

velvet holly
clear crystal
cerulean ravine
velvet holly
#

being able to specify types on multiple declarations on the same line would be useful in many scenarios though

cerulean ravine
velvet holly
turbid sigil
# clear crystal int? boolean? float? str?

they are objects in python. Variables point to the objects that have those types, but the variable itself is not the type. Its like a house address. The street address can be something like "123 easy street", but we have no way of knowing what building is there. The data types of "int, str, float" and more are equivalent to the buildings. The address is the variable name.

cerulean ravine
velvet holly
cerulean ravine
velvet holly
clear crystal
turbid sigil
#

Not necessarily. Its something that will come with time, in my opinion.

velvet holly
#

I don't have a lot of python experience so I'm still trying to figure out the syntax for this kind of stuff

clear crystal
velvet holly
clear crystal
#

R as in rust? if you experience in C++ then it should be a breeze to learn pythob syntax?

velvet holly
clear crystal
#

Oh cool what is R used for?

velvet holly
runic flower
raven urchin
glad egret
#

You could break that problem down into something like this

    #transform input into the right format

function byte_reader(filename):
    with open(filename, 'rb') as f
        return transform_format(r.read())

or into even more pieces like

function transform_format(byte_input):
    #transform input into the right format
    return new_format

function check_format(byte_input):
    if(...some check...){
            return 'xml'
    }else if(...some other check...){
            return 'json'
    }
    return 'default'

function byte_reader(filename):
    with open(filename, 'rb') as f
        contents = f.read()
        found_format = check_format(contents)
        return transform_format(contents, format)

integrated into a decorator for completeness.

def decorator(func):
    def wrapper():
        contents = func()
        found_format = check_format(contents)
        return transform_format(contents, format)

    return wrapper
raven urchin
turbid sigil
clear crystal
#

um what is this?

raven urchin
turbid sigil
clear crystal
brittle merlin
#

this is crazy but what exactly is XML

harsh anchor
#

extensible markup language

brittle merlin
#

can it be used to store data

turbid sigil
# clear crystal what kind of complex function?

for example, in my case, I am reading a file as bytes (one format). I then have a function that converts raw data into a file format. I then have a function that puts the file data read, into a converter to the file format to read the file format.

glad egret
clear crystal
#

only the syntax is familier to me

harsh anchor
hexed grotto
#

hi!

turbid sigil
brittle merlin
clear crystal
#

welp i only know flask currently, nothing else

brittle merlin
#

I need some some json alternatives man

raven urchin
harsh anchor
raven urchin
clear crystal
harsh anchor
brittle merlin
glad egret
#

@turbid sigil by the end ya end up with 6 super duper no side effect functions and 1-2 ones that contain only thinks like reading file.

brittle merlin
ember whale
#

Alo

brittle merlin
turbid sigil
#

okok, I'll commit to that function style for a majority of my work then.

harsh anchor
turbid sigil
#

XML is like a mix of HTML and json, imo

runic flower
#

xml is taking the worst parts of json and combining them with the worst aspects of html
unless you explicitly need the perks of xml you should probably just use json (or toml)

glad egret
#

re: xml; I kind of like node attributes πŸ™‚

clear crystal
#

i literally never heard of XML

brittle merlin
#

I just looked up

XML can do data transfer, whats that supposed to mean?

raven urchin
clear crystal
#

are these things gonna affect me, im tryna learn web dev

turbid sigil
gleaming knoll
#

wow my desktop literally does not work properly at all

runic flower
#

I remember having to parse xml as raw text to figure out which version of xml a doc was using because microsoft's xml 1.1 parser would literally just crash your app if you tried to open a xml 1.0 doc and ask it what version of xml it was. (I might not have the version numbers correct)

harsh anchor
brittle merlin
#

i think learning toml will get me the best ROI

turbid sigil
#

its a good resource, it'll tell you what you want to know for web dev stuff.

gleaming knoll
# gleaming knoll wow my desktop literally does not work properly at all

the systemd network services fail to start on boot but start if i explicitly start them,
the wallpaper daemon starts at the wrong time on the first niri session after boot (it does work if i exit the session and then start again)
this is like, unbearable. i have been debugging this for multiple hours at this point

harsh anchor
raven urchin
clear crystal
raven urchin
#

Also, the network issues are weird

turbid sigil
#

no problem man. enjoy!

brittle merlin
#

yaml

#

for docker

#

toml for python

harsh anchor
#

yaml is a very popular configuration language

brittle merlin
#

XML and JSON for collaborativeness

glad egret
gleaming knoll
brittle merlin
#

is there a python library that renders stuff in any of these formats? (toml yaml json xml)

raven urchin
#

That's what I use

brittle merlin
#

i don't mean render wait

turbid sigil
#

python has json and xml libraries in the std library @brittle merlin

brittle merlin
#

like generates*

gleaming knoll
#

im going to nuke my desktop again tomorrow i swear

raven urchin
gleaming knoll
#

i am inclined to not use a graphical session at all after this tbh
or systemd
or arch

turbid sigil
#

I've had a guide to NIXOS lying around.

#

never gotten to trying it though

raven urchin
#

Maybe it is Niri conflicting with something, last time I tried it it had weird bugs.

#

But more graphical than functional.

turbid sigil
brittle merlin
#

try an AI generated hotfix, modify the startup behaviour or something

raven urchin
#

Also Niri is pretty new

#

Not surprised it has bugs

#

That's why I'm still on Hyprland

clear crystal
#

yep i have no idea lol

gleaming knoll
clear crystal
#

im not a snek

turbid sigil
#

this is not snek stuff, so you're fine.

turbid sigil
#

its operating systems stuff like windows

bitter inlet
#

hi...

clear crystal
#

ohhhhh okay okay

turbid sigil
hexed grotto
#

hello everyone

bitter inlet
#

you summoned me

#

dont be scared

turbid sigil
#

lol

clear crystal
#

bros another level of snek

bitter inlet
#

i am, snek

gleaming knoll
raven urchin
gleaming knoll
raven urchin
brittle merlin
#

make a bash script dude

gleaming knoll
clear crystal
#

bye guys i dont understand those stuff, im gonna go watch toy story now lol

gleaming knoll
hexed grotto
#

why you don't use a voice chat

turbid sigil
raven urchin
#

Also @turbid sigil
See, it's not a Systemd problem by itself, but on how he uses his network, he needs to bypass some stuff to use it. :b

#

I just don't like when people blame the wrong things. πŸ₯€

gleaming knoll
#

the systemd problem is that its really hard to debug

hexed grotto
raven urchin
gleaming knoll
#

i have no entries in it because shit hangs and then just errors

raven urchin
hexed grotto
#

I hope too

gleaming knoll
#

like why does manually doing everything work but nothing works automatedly

hasty sparrow
#

Print ("Hello world")

raven urchin
brittle merlin
#

bro

gleaming knoll
brittle merlin
#

I'm may be forgetting something but did u enable this?

crisp jay
bronze dragon
#

what does the unit file look like?

raven urchin
gleaming knoll
bronze dragon
#

so zapret just hangs (with no stdout/err) when you start it too early?

brittle merlin
#

damn how do u even see the logs for this

u have to use AI to decipher this unless uk grep

brittle merlin
gleaming knoll
brittle merlin
#

@raven urchin teach me linux bro

raven urchin
bronze dragon
gleaming knoll
#

../sysv/zapret is a shell script
and it runs if i run it manually 🀷 but the unit fails on boot

gleaming knoll
#

tbh im not sure what to do with the network-online.target either
it might not be reachable considering systemd-networkd-wait-online was timeouting
i tried changing it but nothing seems to work
sleep then run seems too brittle and disgusting

raven urchin
#

And disbsle network-wait

brittle merlin
gleaming knoll
#

tbh my desktop might be cooked after everything i've done to it today

brittle merlin
#

is it possible the changes they're making aren't persisting?

raven urchin
#

Come back to Hyprland!!!

#

It's cooler now!!!

#

We have everything you need

#

Scripting config, scrolling layout, and anime girl wallpapers :kek:

gleaming knoll
fathom pasture
gleaming knoll
#

im not sure whats the purpose of the wait-online thing at all tbh
it doesnt seem useful on my setup

terse mauve
#

for example

#

Or, tell your DHCP client to boot after NIC is configured by the device drivers

raven urchin
#

Services that need an actual internet connection before they can start (like cloud backup daemons, etc.) declare After=network-online.target so they don't launch into a void. So, for me it kinda is basically useless.

terse mauve
lyric moth
#

Which is the best?
start learning py from books or tuto videos

grave tree
#

It really depends on what works best for you. I do best from something text based

#

!learn

edgy krakenBOT
#
Go-to beginner resources

Here are the top free resources we recommend for people who are new to programming:

For a full, curated list of educational resources we recommend, please see our resources page!

frigid breach
#

Hey, has anyone ever coded anything in finance and quantitative finance? I have some question to ask about the topic!

charred tusk
#

ask your questions

frigid breach
charred tusk
#

There's a few finance people here
Not very many quants tho
But no one can answer the question until you actually ask it

frigid breach
bronze dragon
#

pad?

charred tusk
#

Nope, I refuse to work with that many numbers

cerulean ravine
#

dollars aren't interesting

#

necessary but not interesting

autumn kayak
#

more so

#

A european would rarely do that

obsidian cape
#

what game can i make as a beginner? ( in python)

arctic plank
#

Wsp

arctic plank
cerulean ravine
arctic plank
#

Isnt guessing more simpler

obsidian cape
obsidian cape
cerulean ravine
obsidian cape
arctic plank
#

But I've never tried with words before

arctic plank
bronze dragon
obsidian cape
#

true

arctic plank
#

It isnt only abt coding

rare gazelle
#

hello

bronze dragon
#

also makes you use and combine a number of early-stage concepts, so it's probably a good shout for a beginner

bronze dragon
velvet trout
#

Libraries that went mad? ducky_concerned

bronze dragon
#

yeah, like left-pad

velvet trout
#

What's the meaning of the name

slender urchin
#

!ban 1205209977052991598 racism

edgy krakenBOT
#

:incoming_envelope: :ok_hand: applied ban to @autumn kayak permanently.

terse mauve
obsidian cape
bronze dragon
arctic plank
#

Bruh

bronze dragon
velvet trout
#

now what's ad-libs ducky_concerned

#

Advertisement libraries?

bronze dragon
# obsidian cape why?

there are much better UI libraries for Python, there is no real reason to use Tkinter

velvet trout
#

ad-hoc?

obsidian cape
velvet trout
bronze dragon
bronze dragon
rare gazelle
#

every day you learn something new

stiff fox
#

hello friends

rare gazelle
#

at my age you forget something every day as well

arctic plank
velvet trout
#

Hi bipul

stiff fox
#

hello Aji Romson

rare gazelle
#

1 gets in 1 gets out, fifo

velvet trout
slender urchin
rare gazelle
#

🀣

bronze dragon
summer dagger
#

Is reading books like python crashcourse a good way to avoid the tutorial trap

rare gazelle
#

oh true true, lifo

stiff fox
#

When we define class, it's actually object?

rare gazelle
#

oh, you said lfu, i see, also correct

bronze dragon
cerulean ravine
arctic plank
bronze dragon
#

it's not about the kind of resource you use, it's actually about what you do outside the resource

rare gazelle
#

i tried to create a lfu cache base (decorator) not long ago btw

bronze dragon
arctic plank
#

Some codes require understanding

obsidian cape
bronze dragon
arctic plank
#

Ohk

bronze dragon
#

I mean that whatever you read, the important thing is to make sure you're actually putting it into practice alongside the reading.

#

the important variable in avoiding tutorial hell etc. is whether or not you practice, not whether you read tutorials or books or watch videos

arctic plank
#

I can relate to that

arctic plank
#

Spent a year watching only tutorials

rare gazelle
#

i relied on dictionary being ordered

bronze dragon
#

which, by the way, is why I think that the popularization of the term "tutorial hell" was a mistake

rare gazelle
#

well i still didn't publish it so i won't give more details

bronze dragon
#

way too many people just look at the name and come off with an entirely misguided fear

rare gazelle
#

i think that its easier to just watch the tutorial videos

#

instead of downloading an ide, setting up a venv maybe

glad egret
# rare gazelle i relied on dictionary being ordered

There is a default ordering for regular old dict, and that ordering is likely to never change, but that ordering shouldn't be relied upon. There is a OrderDict class in the stdlib that is there if you do want an ordered dictonary.

arctic plank
bronze dragon
#

although, of course, insertion order might not be useful in your case

rare gazelle
#

its guarenteed to be ordered

arctic plank
#

I'm still not good with def

rare gazelle
bronze dragon
#

watching videos is passive, actually writing code is active

rare gazelle
#

whats easier:
a:
just watching youtubbe tutorials
bb:
watching tutorials and downloading an ide, creating a venv

obsidian cape
rare gazelle
#

like, you dont need almost anything, to just watch the videos

arctic plank
#

I'm going to start learning python again from start

rare gazelle
#

that probably (in my opinion) is the reasoning for the term "tutorial hell"

bronze dragon
arctic plank
arctic plank
bronze dragon
arctic plank
bronze dragon
# rare gazelle that probably (in my opinion) is the reasoning for the term "tutorial hell"

I get the reasoning
but I have seen so many beginners just look at the name, and they go away thinking that reading or watching materials labelled "tutorial" is a sin and they'll ruin their learning if they do that, or such nonsense. and then they're stuck because they don't know how to build anything that does real work, and they've disallowed themselves from using tutorials to learn.

glad egret
# rare gazelle its not just an implementation detail iirc

I think your right, but I would have to look it up too. I didn't know its in the spec these days. Image all the thing that would break if they ever changed the default behavior from long long ago haha.

...but more importantly, relying on something that you have to guess about even if its in the spec is not a foundation I want to build on haha. But that is why OrderedDict exists. to make it explicit that ordering is important and relyed upon.

grave tree
bronze dragon
# arctic plank No, for developing skills

I mean, for a narrow subset of programming skills. but if you are at the stage of "not good with def" as you said, I would suggest spending time on normal Python and building things with it before you grind Leetcode.

soft coral
#

Hi, I'm Chris !
I used to learn many languages like The C family, HTML/CSS, Java, GdScript... But sadly, I can't really code and I want to learn python again.
Should I start from scratch?

rare gazelle
glad egret
edgy krakenBOT
#
Did you mean...

Β» learn-python
Β» learn

pastel sluice
#

!learn @soft coral sorry

edgy krakenBOT
#
Go-to beginner resources

Here are the top free resources we recommend for people who are new to programming:

For a full, curated list of educational resources we recommend, please see our resources page!

velvet trout
sand jewel
#

Hii bye

grave tree
grim socket
#

Hey I’m reading some docs and ran into nested list comprehensions; have you guys ever encountered a real use case similar to: arr = [f"{i}{x}" for x in range(10) for i in range(x)]

pastel sluice
#

id_ is fine.

bronze dragon
pastel sluice
soft coral
craggy willow
pastel sluice
velvet trout
hybrid nebula
pastel sluice
velvet trout
rare gazelle
#

normally i'd use something else though

soft coral
velvet trout
grim socket
craggy willow
arctic plank
edgy krakenBOT
shrewd dune
#

I am so sorry for asking, i just started 2 weeks ago. How hard is learning and mastering python. Kinda stuck at functions right

soft coral
pastel sluice
velvet trout
grave tree
pastel sluice
arctic plank
rare gazelle
craggy willow
rare gazelle
#

get_id

pastel sluice
rare gazelle
#

id_of

stiff fox
prime mountain
shrewd dune
#

Yeah sql was way easier then python. Mind u this is my first real programm.

velvet trout
grave tree
soft coral
swift sparrow
pastel sluice
bronze dragon
soft coral
swift sparrow
#

Product is the blueprint. Product() is the constructed object

soft coral
#

I ain't

grave tree
#

Some other tutorials focus on stuff specific to the language, not programming in general. The new-to-programming-and-python resources we have are longer because they also teach fundamental concepts like loops

stiff fox
tawdry bolt
#

@Helpers Hey, can I learn to code python here?

arctic plank
pastel sluice
#

@soft coral ok, you need to tell us what you actually want, then.

bronze dragon
# soft coral No

CS50 is structured as a college-level introduction to Computer Science. so it is in the format of hour-long lectures and exercises.
there are other tutorials, with other formats.

soft coral
pastel sluice
swift sparrow
grim socket
grave tree
#

You don't have to learn Python, but if you do want to learn Python we're here!

velvet trout
arctic plank
bronze dragon
soft coral
grave tree
soft coral
grim socket
arctic plank
pastel sluice
#

@soft coral no matter what language you pick or what kinds of programs you want to write, you'll have to learn how things work in some form.

grave tree
craggy willow
velvet trout
swift sparrow
bronze dragon
#

if you don't like CS50, again, there are many other tutorials in different formats.
The Python MOOC 2026 is text-based, for example. Automate the Boring Stuff is a literal book.
@soft coral

soft coral
velvet trout
#

Is __builtins__ guaranteed to be always present?

grim socket
velvet trout
swift sparrow
grave tree
soft coral
rare gazelle
#
check_id = id

class A:
  def __init__(self, id: int) -> None:
    self.id = check_id(id)  # suppose i needed memor\
grim socket
raven urchin
grave tree
#

But also if you're interested in games specifically, I would especially take advice from Fashoomp. It's kinda his area. Also Infini has made some cool games

bronze dragon
swift sparrow
autumn forge
swift sparrow
grim socket
soft coral
raven urchin
bronze dragon
swift sparrow
velvet trout
# grim socket Lol sorry I’m not sure what the context is rn

The context is, id is a built-in name of python, but in lots of programs, id is a common name and could collide with the built-in id function and overshadow it. The suggested workaround is a trailing underscore after the name id + _ = id_. i kind of think it is not so pleasing (at least to me). So i was wondering how people work around it.

glad egret
# rare gazelle you've got a point i guess

I think you are going to find some weird edge cases where you dont want to link the internal object id with internal python object id. If you need the id to be unique I would suggest the uuid class.

raven urchin
# soft coral Bcz I can't code idk what I have

Hey.
I consider myself being PRETTY dumb. And even I am doing my best to learn how to code. Thanks to my efforts and the help of people at pydis, like shoomp, I've been able to create amazing stuff. ;)

Give it a try, if you truly are interested, you'd be surprised of what you can make with your own hands and mind.

grim socket
glad egret
stiff fox
velvet trout
grim socket
arctic plank
craggy willow
cerulean ravine
soft coral
raven urchin
swift sparrow
craggy willow
summer dagger
#

Guys does it count if i type with my screen facing away and call it backend development

grim socket
arctic plank
raven urchin
grim socket
craggy willow
stiff fox
rare gazelle
#

i wonder if the hash of a number is the same object as the original number...

velvet trout
rare gazelle
#

if its under 2^31

glad egret
bronze dragon
#

for 2**31 it is not

rare gazelle
#

hash(5000) is 5000 False

#

thats such a waste of memory

grim socket
brittle slate
#

How would you make a loop to make this shorter:

pi = [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9]
print(pi[0])
print(pi[1])
print(pi[2])
print(pi[3])
print(pi[4])
print(pi[5])
print(pi[6])
print(pi[7])
print(pi[8])
print(pi[9])
print(pi[10])
print(pi[11])
print(pi[12])
print(pi[13])
print(pi[14])

grave tree
rare gazelle
#

a = 5000
b = hash(a)
print(a is b)  # False
velvet trout
#

wouldn't you do == ?

brittle slate
swift sparrow
spice hill
rare gazelle
#

everytime you hash an integer it creates an object, wtf

#

waste of memory and performance

velvet trout
rare gazelle
#

in a set for every number there are 2 slots taken (its hash an the actual number)

velvet trout
viscid coral
rare gazelle
#

56 bytes for every number in a set

terse mauve
glad egret
craggy willow
brittle slate
spice hill
grim socket
swift sparrow
cerulean ravine
rare gazelle
craggy willow
#

those are the only real ints

#

fake ints don't count

grim socket
rare gazelle
rare gazelle
craggy willow
#

ned, when did you change colors

spice hill
#

(a 64-bit int actually takes up to 36 bytes, not 28)

craggy willow
#

oh, pycon attendee

#

nice

grim socket
cerulean ravine
craggy willow
#

oh no!

#

i hope i can see some of the talks online

cerulean ravine
grim socket
craggy willow
edgy krakenBOT
rare gazelle
gilded star
#

me

glad egret
grim socket
rare gazelle
terse mauve
rare gazelle
#

why's that

#

-1 is reserved for error or something?

cerulean ravine
rare gazelle
#

πŸ‘

raven urchin
#

Production products

#

Idk why "production ready" and phrases like that always seem funny to me

coarse salmon
#

all you do is copy paste this every few days

cerulean ravine
#

you've said that a few times. Why are you telling us?

terse mauve
young flare
#

buzzword buzzword buzzword

vital ice
#

there is no answer or reply to my message in couple days, lol

summer dagger
bronze dragon
#

what answer do you expect?

rare gazelle
#

what he said

summer dagger
rare gazelle
#

if only i had the power of the mods to see deleted messages...

vital ice
main swan
#

if only i had the power of mods to react with emojis.

bronze dragon
glad egret
# grim socket Maybe there’s difference definitions for levels of abs cause the match case logi...

I don't think I understand. I think of the id you get back from the global id function like a memory address(I'm not sure if its an actual memory address)

But if I need to make a class that had a unquie id attribute I would do something like

@dataclass
... class Foo:
... id: str = uuid4()
...

f = Foo()
f.id
UUID('68b90467-369b-4f39-a81b-4379c9ef6533')
id(f)
127181685461008

ya have your pick of like 8 uuid function. some are guaranteed to be unique some or just really really likely. some leak sensitive info.

cerulean ravine
young flare
summer dagger
bronze dragon
#

it is lol

vital ice
raven urchin
cerulean ravine
terse mauve
edgy krakenBOT
#

9. Do not offer or ask for paid work of any kind.

young flare
summer dagger
#

At first i thought vibecoding was just being lazy and coding while watching netflix or something

obsidian cape
#

i decided to use discord instead of AI, How to check if entry output (from tkinter) is of length 5 and then remove it?

summer dagger
#

But yeah using ai and not even checking it is crazy

raven urchin
spice hill
terse mauve
rare gazelle
raven urchin
terse mauve
raven urchin
rare gazelle
#

in 32 it uses 30, in 64 it can use 60

cerulean ravine
rare gazelle
terse mauve
#

nooooooo, the linux mirror at github has disabled PRs. one of the funniest PRs was deleted. it was a guy fixing a "typo" and made a pr to make everything from long long -> long

final hollow
#

Github uses Java..?

spice hill
#

they should've made it loong instead of long long

main swan
raven urchin
#

longong

spice hill
#

and u128 would be looong

final hollow
#

Ruby has long longs?

terse mauve
final hollow
#

I thought Ruby didn't have explicit static typing

spice hill
terse mauve
spice hill
raven urchin
#

torvals/linux

Aura πŸ—£οΈ πŸ”₯

terse mauve
#

there were so many funny PRs there

final hollow
#

Oh. They use long long instead of fixed width integers in the repository? Interesting

raven urchin
#

What even is a long long

#

It sounds too funny to be real

velvet trout
#

float i think pithink

wise imp
#

long long is definitely not a float

final hollow
velvet trout
#

then my next guess is A VERY LONGGGGG NUMBER

civic turret
#

Guys i have my leaving cert computer science exam tomorrow it has a section C python based part where u have t9 code any tips

#

Ik the basics n like to use tab instead of space

final hollow
#

But since it's C++ there's no guarantees on integer sizes

raven urchin
cerulean ravine
civic turret
#

Ik loops n all but I still dont understand how functions work

terse mauve
cerulean ravine
main swan
final hollow
# raven urchin pretty descriptive

Yeah in modern C/C++ you don't really see it.. C and C++ don't guarantee the sizes of integers (it just has guaranteed minimum sizes relative to the smaller types). So an int on one system could be 64 bits, but could be 32 bits on another system.

real crescent
#

can sm1 recommend a project to do as a python beginner

terse mauve
edgy krakenBOT
#
Print and return

Here's a handy animation demonstrating how print and return differ in behavior.

See also: /tag return

real crescent
terse mauve
rare gazelle
edgy krakenBOT
#
Kindling Projects

The Kindling projects page contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

rare gazelle
#

longest

real crescent
#

okay thankyou

raven urchin
final hollow
# raven urchin o

The reason why varies due to CPUs and operating systems. It's convoluted. That's why we use fixed width integers instead (uint32_t for unsigned 32 bit int for example)

main swan
#

i like it.

rare gazelle
#

😁

raven urchin
main swan
rare gazelle
spice hill
#
#define tall int
#define grande long int
#define venti long long int
rare gazelle
final hollow
#

C++ is extremely large. Many people just use subsets of the language because of how vast it is. C grants more explicit control without abstraction, but has fewer niceties

rare gazelle
#

thinking about it, in github issues, people tend to be nicer, compared to stackoverflow

raven urchin
bronze dragon
main swan
rare gazelle
terse mauve
main swan
terse mauve
raven urchin
main swan
raven urchin
rare gazelle
#

C# was my first language, C second iirc

bronze dragon
main swan
rare gazelle
terse mauve
raven urchin
bronze dragon
rare gazelle
#

or simpler...

#

but i think that python can be a good languge for beginners

terse mauve
raven urchin
#

It made me understand programming basics. :D

rare gazelle
#

the thing with python is that it's not pushing you to use classes and namespaces

#

and letting you progress at your own pace, without many strict rules preventing you from starting

bronze dragon
#

yeah
it's high-level, has easy-to-read syntax, not much boilerplate, and can do a ton of practical things due to its ecosystem

prime mountain
#

I just read up on classes

rare gazelle
#

yea

bronze dragon
#

!zen namespaces

edgy krakenBOT
#
The Zen of Python (line 18):

Namespaces are one honking great idea -- let's do more of those!

raven urchin
#

what 😭

rare gazelle
#

its hard for me to define it

bronze dragon
#

namespaces let you group names into a single entity, so something like a module acts as a namespace for everything defined inside it.

#

literally, a space for holding names.

rare gazelle
#

a module in python for example, yea

rare gazelle
#

name - spaces, spaces for names

raven urchin
#

So like, a class and its methods count too?

bronze dragon
raven urchin
#

Yay

prime mountain
#

Is method calling of classes a use of namespaces?

#

Or have I gotten it wrong?

rare gazelle
#

in python anything you do . is namespaces forwarding, if you understand what i'm saying

#

on names i mean

#

not 5.14

prime mountain
#

Okay yeah...

rare gazelle
#

the descriptor protocol is also very interesting

#

eivl taught me a lot about it

prime mountain
#

So much stuff I want to learn..

#

So little time...

rare gazelle
#

its a bit complicated topic though

#

basically it's regarding namespaces, what object you get in return, when you call for a name

terse mauve
#

Andrej Karpathy is joining anthropic ducky_concerned

rare gazelle
#

who's that

bronze dragon
#

AI researcher

terse mauve
#

openAI co-founder

rare gazelle
#

i see

prime mountain
raven urchin
#

😭

velvet trout
#

DID SOMEONE JUST MENTION DESCRIPTOR PROTOCOL?

#

holy peak mentioned

terse mauve
velvet trout
ocean ridge
raven urchin
velvet trout
#

Even science cannot explain it

raven urchin
velvet trout
#

Ever wonder how your instance methods get self implicitly without having you explicitly pass it?

velvet trout
rare gazelle
#

yea also part of the descriptor protocol

velvet trout
#

Ever wonder how @property makes a function an attribute without calling by () ?

rare gazelle
#

you know quite a lot about the descriptor protocol

velvet trout
#

Why do you think i do not

rare gazelle
#

thats right, property also uses it

raven urchin
rare gazelle
velvet trout
#

I just bad at explaining πŸ˜”

velvet trout
rare gazelle
#

_._

velvet trout
rare gazelle
#

its an interesting topic indeed

rare gazelle
#

or anyone else other than you

arctic plank
#

Hi

rare gazelle
#

you need to learn it properly, in my opinion, in order to understand it

velvet trout
#

I forgot how the lookup for that happens

#

But the first time i learnt about it and used it β€” it was a beautiful experience of such a phenomenon

tawdry bolt
#

<@&831776746206265384> hey, where do we learn python guys?

bronze dragon
grave tree
edgy krakenBOT
#
Go-to beginner resources

Here are the top free resources we recommend for people who are new to programming:

For a full, curated list of educational resources we recommend, please see our resources page!

steady rain
#

!mute @tawdry bolt "3 days" maliciously pinging moderators

edgy krakenBOT
#

:incoming_envelope: :ok_hand: applied timeout to @tawdry bolt until <t:1779476629:f> (3 days).

velvet trout
rare gazelle
rare gazelle
raven urchin
steady rain
#

@tawdry bolt in case you didn't realize, this isn't a funny joke. Moderators get dozens of pings a day and your behavior contributes to mod burnout.

velvet trout
raven urchin
#

I don't really know how to write them properly, but I kinda know what they do.

arctic plank
velvet trout
velvet trout
raven urchin
#

Let's see

arctic plank
velvet trout
#

Might also have lookup and other technical details which is good to know to understand

burnt marlin
#

hi

arctic plank
velvet trout
#

hi the ultimate lifeform but faster

velvet trout
arctic plank
#

Winning is everything

velvet trout
#

True

#

πŸ—Ώ

arctic plank
#

That's why I'm gonna win

velvet trout
#

Nah, I'd win.

#

.topic

verbal wedgeBOT
#
**What was the first thing you created with Python?**

Suggest more topics here!

rare gazelle
# raven urchin Yes
class my_property:
  def __init__(self, fn):
    self.fn = fn

  def __get__(self, instance, owner):
    return self.fn(instance)


class a:
  def __init__(self, name):
    self.name = name

  @my_property
  def get_name(self):
    return self.name


a_instance = a("jason")

print(a_instance.get_name)
buoyant finch
#

With a dataclass, if I define a __post_init__ method, does that code run as part of the call to __init__?

In my use-case, the __post_init__ does some validation to make sure that the class is set up correctly, and raises an exception if not.

If I try/catch the call to MyClass(foo, bar, baz), I'll catch exceptions raised in __post_init__, right?

rare gazelle
#

watch this, my_property is a simple implementation of a property

velvet trout
arctic plank
raven urchin
rare gazelle
#

when doing @my_property its like doing my_property(get_name), so it creates a property object

floral terrace
#

why the topic changed lmao

spice hill
velvet trout
rare gazelle
velvet trout
rare gazelle
velvet trout
#

Yup!

rare gazelle
burnt marlin
terse mauve
frosty oriole
#

When defined on the class, it will be called by the generated __init__(), normally as self.__post_init__()
hm

spice hill
#

!e

from dataclasses import dataclass

@dataclass
class Foo:
    field: object
    def __post_init__(self):
        print("post_init")

class Bar(Foo):
    def __init__(self):
        print("evil init that doesn't call __post_init++")
print("calling Foo")
Foo(1)
print("calling Bar")
Bar()
viral vale
#

If i am already familiar with data science what i can start learning
Flask or node js for the backend

velvet trout
raven urchin
edgy krakenBOT
rare gazelle
arctic plank
rare gazelle
#

its very useful

#

sadge it isn't

rare gazelle
burnt marlin
finite sigil
#

Does anyone even codes by themselves nowadays ?

#

AI kinda killed coding right ?>

spice hill
#

of course (to the first message)

terse mauve
edgy krakenBOT
#

Lib/functools.py line 1021

class singledispatchmethod:```
arctic plank
rare gazelle
#

say you want to add some logic to init, you're fucked

finite sigil
rare gazelle
#

must implement init, with all arguments, call super

terse mauve
floral terrace
terse mauve
rare gazelle
#

all you do with the arguments is pass them to super

#

pretty much pointless shit

rare gazelle
#

and if there're overloads, you're fucked even more

rare gazelle
#

need to include all those in your class

arctic plank
#

Well see ya

spice hill
arctic plank
rare gazelle
#

post_init should be for all classes to avoid this shitty problem

finite sigil
rare gazelle
terse mauve
pastel sluice
rare gazelle
#
a_instance.get_name
^namespace ^name
spice hill
raven urchin
rare gazelle
raven urchin
#

#bot-commands

pastel sluice
terse mauve
rare gazelle
spice hill
rare gazelle
rare gazelle
#

are you for real

terse mauve
velvet trout
rare gazelle
terse mauve
rare gazelle
#

the idea of it

dull dune
#

wyou can type kwargs at least wtih typeddict now

terse mauve
rare gazelle
#

dude i explained it all like 5 messages ago

spice hill
terse mauve
velvet trout
#

Why do other programming languages need new keyword to create a new of a object?

in python, dunder new is called by type's dunder call i guess?

wise imp
# finite sigil Source?

There are also companies that simply can't allow an external AI-product to be used internally for producing code due to various regulations or policies, because it's a risk factor. In those cases they might I guess self-host an LLM, but I wouldn't know about that, I have heard somewhere that some companies do do that however.

rare gazelle
pastel sluice
dull dune
rare gazelle
#

maybe i'll just create a post_init dunder

#

but i dont know how, a metaclass perhaps

spice hill
# rare gazelle ...

I'm still not sure what the problem is, if we ignore type checking concerns.

rare gazelle
#

maybe you'd wrap init to call it after its finished or something...

finite sigil
dull dune
#

also because of python's brand of duck typing

#

it makes it really easy, classes are callable

rare gazelle
dull dune
#

so you can call them

terse mauve
# rare gazelle how
from abc import ABCMeta, abstractmethod

class MyMeta(metaclass=ABCMeta):
  @abstractmethod
  def setup():
    pass
rare gazelle
spice hill
terse mauve
rare gazelle
#

solved

spice hill
rare gazelle
#

why not though

velvet trout
#

The lack of underscore between abstract and method is concerning me ducky_concerned

dull dune
#

generally if it's a 2-word phrase and not hard to understand at a glance it's fine to not use a _ between words. I think abstractmethod is pushing it by length alone, but...

rare gazelle
velvet trout
raven urchin
spice hill
# rare gazelle why not though

We could instead fix the core issue and add something for forwarding *args, **kwargs. For example: if @typing.override is applied to a function with *args, **kwargs, then they are not assumed to be Any and Any, but rather to be the arguments to the parent method. This would also fix the same issue for methods other than __init__, along with not adding more stuff to the language.

raven urchin
#

I saw a cool example on the docs about a DirectorySize

rare gazelle
pastel sluice
# finite sigil The people around me and in the previous firm

I write for a publication that is aimed at enterprise software developers. There's a lot of interest in AI for writing software, no question about it. There is also at least as much skepticism about it, and serious questions about how sustainable the whole practice is, and discussions around how generating tons of code on demand is actually a net burden and not an asset

rare gazelle
#

its more of a solution if u need the arguments

#

but if you dont need the arguments, post_init is a pretty solid option

barren sentinel
#

I’m actually getting rage baited by type checkers right now. I try to write some nice clean match code, no type checker supports the narrowing. I try to write it using explicit instance checks, still no support. I end up having it write it in a much less clear form.

terse mauve
velvet trout
#

Getting rage baited by a type checker? Lmao

rare gazelle
barren sentinel
raven urchin
velvet trout
#

!doc functools.cached_property see also

edgy krakenBOT
#

@functools.cached_property(func)```
Transform a method of a class into a property whose value is computed once and then cached as a normal attribute for the life of the instance. Similar to [`property()`](https://docs.python.org/3/library/functions.html#property), with the addition of caching. Useful for expensive computed properties of instances that are otherwise effectively immutable.

Example...
rare gazelle
terse mauve
edgy krakenBOT
#

@functools.cached_property(func)```
Transform a method of a class into a property whose value is computed once and then cached as a normal attribute for the life of the instance. Similar to [`property()`](https://docs.python.org/3/library/functions.html#property), with the addition of caching. Useful for expensive computed properties of instances that are otherwise effectively immutable.

Example...
velvet trout
raven urchin
#

But without yanking it out

terse mauve
rare gazelle
velvet trout
raven urchin
rare gazelle
raven urchin
#

It's like

velvet trout
#

I think cached_property doesn't work for frozen dataclasses? Idk i think i had an issue once...

rare gazelle
#

init gets the same arguments new is getting, its not a big stretch for post_init to get those arguments as well

terse mauve
terse mauve
velvet trout
#

Oh i see, i did had slots=True

terse mauve
#

because defining __slots__ means that you have no __dict__

raven urchin
terse mauve
# raven urchin Well, I got more confused lol

imagine we have a very computation intensive function, instead of returning the result right away, we "memorize" which arguments returns which values, so if we get called again with the same arguments

raven urchin
#

cache is a dict
my property returns the "res" of cache if "res" is in cache

res = heavy func
cache["res"] is then set to res
and returns res?

rare gazelle
terse mauve
rare gazelle
#

there's a default for metaclass call....
it calls the new and then init

#

what if you override call (to also call post init if it exists)

barren sentinel
raven urchin
rare gazelle
#

another option is for it to always exist

grim socket
#

how to screen share please ? I want to go over python docs in VC0

rare gazelle
#

and to always call it

velvet trout
#

And i don't think type checker is wrong? It just cannot prove that for first case the .content will be definitely a string

Can it? pithink ducky_concerned

barren sentinel
#

For the first one? It should be. Either it’s ItemToken + content str, or StringToken, which is content str by default.

velvet trout
#

ItemToken(str()) never used like this, i haven't tried for attributes

barren sentinel
velvet trout
#

I see

jagged belfry
#

!e ```py
from dataclasses import dataclass

Item = int | str

@dataclass
class A:
item: Item
second: str

def foo(a: A):
match a:
case A(int()):
print("int", a.item)
case _:
print("str", a.item)

print(foo(A(1, "b")))
print(foo(A("a", "b")))

raven urchin
#

None?

edgy krakenBOT
jagged belfry
#

or

#

maybe not

#

sigh

#

I misread it

barren sentinel
#

No? You don’t need to provide every entry in a match, your first code worked as expected/the same as the second

jagged belfry
#

yeah I misread the answer

barren sentinel
#

Oof

jagged belfry
#

Yeah so I guess it works fine

#

So, type checkers just don't do that I guess

#

it might be an intersection of the dynamic dataclass support and match narrowing

barren sentinel
#

Which is major levels of bullying

jagged belfry
#

does the same fail typechecking if you've manually written __init__?

barren sentinel
grim socket
#

Can one mutate a mutable object inside a tuple ?

grim socket
#

so where is the tuple being inmutable line drawn

bronze dragon
grim socket
#

but you could reasign an element in a list thats nested inside a tuple ?

bronze dragon
#

sure

brisk gazelle
#

Don't think of tuples and lists as containers of objects, but of references to objects.

bronze dragon
#

you can think of it as, the tuple only cares that the references it holds do not change
the objects being referred can change however they want

grim socket
#

wouldn't that change the tuple ? thus being a mutated tuple not the same tuple as before?

bronze dragon
#

from the tuple's perspective, it is still referring to the same objects at any point. but you're right. a deepcopy of the tuple at one point in time may not compare equal to a deepcopy at a different point in time.

grim socket
#

so it just holds an identity check guard for it's immutability definition ?

tidal lily
tidal lily
floral terrace
bronze dragon
floral terrace
#

ye, imagine tuple as something like that

bronze dragon
#

i.e. tuple.__setitem__ and tuple.__delitem__ always throw an error, and there is no such method as tuple.append, etc.

golden mortar
bronze dragon
#

so, there are no simply no allowed means for you to modify the tuple in the senses it cares about

tidal lily
#

!e
a = "Hello"
b = (a,)
b[0] = a

edgy krakenBOT
# tidal lily !e a = "Hello" b = (a,) b[0] = a

:x: Your 3.14 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 3, in <module>
003 |     b[0] = a
004 |     ~^^^
005 | TypeError: 'tuple' object does not support item assignment
tidal lily
#

Doesn't work, doesn't matter what you're assigning

grim socket
arctic plank
#

This is the simplest guessing game ever

import random

while True:
    number = int (input("Enter your guess:"))
    dice = random.randint(1,10)
    
    if number == dice:
        print ("Congrats")
        break
    else:
        print (" sorry")
    
    
grim socket
#

the objects may mutate there states but the references stay the same thus mutable elements in a tuple can be mutated

terse mauve
tidal lily
bronze dragon
#

tuples could have disallowed mutable members in the same way that sets/dicts do, but idk if that would have been a good idea
probably not?

gleaming knoll
tidal lily
#

sigh I upgraded to windows 11 and now the 8 versions of Python I installed in the past 6 years no longer work

proud nacelle
#

Quick sanity question. Will continue allow the program to progress to write_06H_register() or go back to the top of the try block?

def input_06H_register():
    while True:
        try:
            register = int(input("Register (decimal or 0x hex): "), 0)
            value = int(input("Value (decimal or 0x hex): "), 0)
            controller_id = int(input("Controller ID (1-32): "), 0)
            if not (1 <= controller_id <= 32):
                print("Invalid controller ID! Must be 1-32.")
                continue
            write_06H_register(
                                register, 
                                value, 
                                controller_id)
arctic plank
bronze dragon
#

yes, turn them into a list

gleaming knoll
terse mauve
grim socket
velvet trout
grim socket
proud nacelle
bronze dragon
tidal lily
gleaming knoll
grim socket
terse mauve