NameError: global name 'myExample2' is not defined # modules

后端 未结 5 1634
栀梦
栀梦 2021-01-12 03:48

Here is my example.py file:

from myimport import *
def main():
    myimport2 = myimport(10)
    myimport2.myExample() 

if __name__ == \"__main_         


        
5条回答
  •  天命终不由人
    2021-01-12 04:10

    You have to create an instance of the myClass class, and not the instance of the whole module(and i edit variables names to be less awful):

    from myimport import *
    def main():
        #myobj = myimport.myClass(10)
        # the next string is similar to above, you can do both ways
        myobj = myClass(10)
        myobj.myExample() 
    
    if __name__ == "__main__":
        main()
    

提交回复
热议问题