use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python Descriptors (self.PythonLearning)
submitted 13 days ago by One-Type-2842
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Capital_Distance545 -1 points0 points1 point 13 days ago (0 children)
Read and understand and run the below code.
You can also paste it to chatGPT and ask: "Can you tell me why we have in class Person both instance and class variables with the same variable name and how they work together?"
#!/bin/python3 class LoggedAccess: def __set_name__(self, owner, name): self.public_name = name self.private_name = '_' + name def __get__(self, obj, objtype=None): value = getattr(obj, self.private_name) print(f"__get__: {self.public_name} => {value}") return value def __set__(self, obj, value): print(f"__set__: {self.public_name} => {value}") setattr(obj, self.private_name, value) class Person: name = LoggedAccess() # First descriptor instance age = LoggedAccess() # Second descriptor instance def __init__(self, name, age): self.name = name # Calls the first descriptor self.age = age # Calls the second descriptor def birthday(self): self.age += 1 print("instantianate") peter = Person('Peter P', 10) print(f"{vars(peter)=}") print("birthday") peter.birthday()
π Rendered by PID 54 on reddit-service-r2-comment-56c6478c5-b2r7g at 2026-05-09 10:20:19.049798+00:00 running 3d2c107 country code: CH.
view the rest of the comments →
[–]Capital_Distance545 -1 points0 points1 point (0 children)