I use python3.
It is not recognized when another function is called from a function in the class.
here my code and error message
These codes erase all the complex stuff, and only the ones that matter. I just want to call get_contents() in the main function. And get_contents() should call get_response().
class TClass:
def get_response():
return 'response'
def get_contents():
content = get_response()
return content
if __name__ == "__main__":
contents = get_contents()
print (contents)
Traceback (most recent call last):
File "/Users/mul/Project/mybase.py", line 2, in <module>
class TClass:
File "/Users/mul/Project/mybase.py", line 11, in TClass
contents = get_contents()
File "/Users/mul/Project/mybase.py", line 7, in get_contents
content = get_response()
NameError: name 'get_response' is not defined
help me. please
"""
I am studying Python by looking at the documents. I didn't know that the main function had to be outside the function.
Thanks to everyone who helped, even though it was too easy.
"""
question from:
https://stackoverflow.com/questions/65643230/there-is-a-problem-when-calling-another-function-from-a-function-in-the-same-cla 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…