I am new in programming and I have faced a problem for which I can't find an answer... So here it is:
`class MyClass:
def printsmth():
print("Hello")
def main():
printsmth()
if __name__ == '__main__':main()`
I get an error which says :
Traceback (most recent call last):
File "untitled.py", line 1, in <module>
class MyClass:
File "untitled.py", line 6, in MyClass
if __name__ == '__main__':main()
File "untitled.py", line 5, in main
printsmth()
NameError: name 'printsmth' is not defined
Code included is just an example, but it is the same error that I get on my real code, if for example I would transfer my code from main() to if name == 'main' than it works perfectly. The thing is that I want to relaunch main() method in some parts of the code but I haven't even gone to that because I can't think of a solution to this error:/ Can you help me?
P.S I tried to move main() and if name == 'main' from MyClass and it didn't worked.