简体   繁体   中英

Python not recognising another file

I am creating a python module. To test it i put the file in the same directory and then wrote the code

import mymodule
mymodule.dofunction

python then said >>>no module named mymodule but they are in the same directory.

Adapting from previous answer here . Explicitly state that you want to use the current directory.

Also, consider that you need an "__init__.py" file in each directory you are importing from.

import os, sys
lib_path = os.path.abspath('.')
sys.path.append(lib_path)

import mymodule

More information on the import system here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM