Hello everyone, I have a class, where I have a function pip which I use in function wash, but I have a problem, that the python does not know the values up and down, which I defined below. How can I do it? I just need to define them below, not in the init. Is that posiible? Thank you
def pip(self, up, down):
def wash(self, w1, w2, up, down):
w1 = 5
w2 = 2
up = 0
down = 3
program.wash(w1, w2, up, down)
Are you both aware that deleting your own posts still leaves enough residue for people to read the posts, but it forces us to click a thing to see the post? Posts don’t really delete here.
…and that is precisely why I added this, for all who look at that residue to see, prior to my deleting my posts, which was done in reaction to observing that nearly all the essential context had been deleted from the thread by the OP:
Upon rereading the posts within this discussion, it appears to me that the deletion of two posts by the OP has obfuscated the essential context of the thread. Therefore, I will be deleting this and my previous replies.
Inside a function, and that includes methods within a class, we can define local variables. Those variables will persist until the function terminates. Prior to that termination, we can use those variables as components of expressions that serve as arguments for calling other functions.
If we wish to define variables that persist throughout the existence of an instance of a class, we can define instance variables. Those variables are often initialized within an
__init__ method, but that can also be accomplished within other methods.
Another option is to create class variables. See 9.3.5. Class and Instance Variables.