(Jan-15-2021, 01:16 PM)hobbyist Wrote: So, you imply return variables of each function?
Let's start by saying you have SyntaxErrors in your code. Then, if it was just functions it's better to take arguments and then return the result.
Because it is a supposedly class (i.e. OOP) you can add and use attributes. But before that you need to fix the structure of your class (e.g. make the functions methods, not nested functions inside
__init__()
method. And if the functions don't need access to instance or class, you should ask yourself does it really belong to the class.This makes it easier to debug and test your code, reuse it and so on.
(Jan-15-2021, 12:55 PM)hobbyist Wrote: Do I miss something here?Also, what you have here is just the class definition, you never instantiate your class so that it execute (after you fix the multiple problems)
So this work, but it's BAD code and you should not do it:
sentence_1 = "hello" sentence_2 = "hello" class MyClass: def __init__(self, parent = None): # do something def function_A(): # do something ... global sentence_1 sentence_1 = "new string 1" def function_B(): # do something ... global sentence_2 sentence_2 = "new string 2" function_A() function_B() spam = MyClass() print(sentence_1) print(sentence_2)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs