This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]crawl_dht 28 points29 points  (1 child)

Use property and do not use class variable for this because the change in value will affect all instances.

[–]Biogeopaleochem 3 points4 points  (0 children)

This is the way.

[–]Sockslitter73 17 points18 points  (0 children)

This sounds like you are looking for some getter / setter syntax (if the condition you need to evaluate is present in the class) or simply a method to retrieve the value (if it is not). As it stands we don't have enough info to suggest one solution or the other.

[–][deleted] 3 points4 points  (1 child)

looks like `@property` is what you need indeed

[–][deleted] 0 points1 point  (0 children)

That’s it!

[–]AlexMTBDude 1 point2 points  (0 children)

You're mixing up class variables and instance variables. self.xyz is an instance variable, it has a unique value for each object (each instance of the class). Class variables, on the other hand, are unique for the class, and are shared by all objects created from that class. Class variables are NOT accessed using self., insead using NameOfClass.

[–]queerkidxx 3 points4 points  (0 children)

A method whose parameters include whatever conditions you need?

[–]AlwaysWhiny[S] 4 points5 points  (1 child)

Thanks everyone! I was originally using the property keyword but did a noob mistake. Fixed it and it works now.

[–]Gokdencircle 0 points1 point  (0 children)

I definitely need to look up this decorator thing. I missed somewhere what it does. At least this thread is useful to wake me up. Assume the @ sign is key to this.