module import: NameError: name is not defined

后端 未结 3 399
一个人的身影
一个人的身影 2021-01-23 19:08

How do I define the function in the importer so that it is visible inside imported? I tried this

importer.py is

def build():
    print \"bui         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 19:37

    importer.py

    def build():
       print("building")
    
    build() #this extra call will print "building" once more.
    

    imported.py

    from importer import build
    build()
    

    Note that both importer.py and imported.py must be in same directory. I hope this solve your problem

提交回复
热议问题