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

后端 未结 5 1539
栀梦
栀梦 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

    First, I agree in with alKid's answer. This is really more a comment on the question than an answer, but I don't have the reputation to comment.

    My comment:

    The global name that causes the error is myImport not myExample2

    Explanation:

    The full error message generated by my Python 2.7 is:

    Message File Name   Line    Position    
    Traceback               
            C:\xxx\example.py   7       
        main    C:\xxx\example.py   3       
    NameError: global name 'myimport' is not defined
    

    I found this question when I was trying to track down an obscure "global name not defined" error in my own code. Because the error message in the question is incorrect, I ended up more confused. When I actually ran the code and saw the actual error, it all made sense.

    I hope this prevents anyone finding this thread from having the same problem I did. If someone with more reputation than I wants to turn this into a comment or fix the question, please feel free.

提交回复
热议问题