這裏是我的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()' –