Ecco il mio example.py
di file:NameError: moduli nome globale 'myExample2' non è definita #
from myimport import *
def main():
myimport2 = myimport(10)
myimport2.myExample()
if __name__ == "__main__":
main()
Ed ecco myimport.py
di file:
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
Quando eseguo example.py
di file, ho il errore seguente:
NameError: global name 'myExample2' is not defined
Come posso risolvere il problema?
è necessario 'myExample2 (self, num)' e quindi fare riferimento ad esso come 'self.myExample2() ' –