Вот мой example.py
файл:NameError: глобальное имя 'myExample2' не определен # модули
from myimport import *
def main():
myimport2 = myimport(10)
myimport2.myExample()
if __name__ == "__main__":
main()
А вот myimport.py
файл:
class myClass:
def __init__(self, number):
self.number = number
def myExample(self):
result = myExample2(self.number) - self.number
print(result)
def myExample2(num):
return num*num
Когда я бегу example.py
файл, я есть следующая ошибка:
NameError: global name 'myExample2' is not defined
Как это исправить?
вам нужно 'myExample2 (self, num)', а затем ссылаться на него как 'self.myExample2()' –