Python name 'os' is not defined even though it is explicitly imported

前端 未结 2 1985
花落未央
花落未央 2021-02-13 13:14

I have a module called imtools.py that contains the following function:

import os 

def get_imlist(path):
    return[os.path.join(path,f) for f in o         


        
2条回答
  •  逝去的感伤
    2021-02-13 13:45

    Based on small hints, I'm going to guess that your code didn't originally have the import os line in it but you corrected this in the source and re-imported the file.

    The problem is that Python caches modules. If you import more than once, each time you get back the same module - it isn't re-read. The mistake you had when you did the first import will persist.

    To re-import the imtools.py file after editing, you must use reload(imtools).

提交回复
热议问题