简体   繁体   中英

Why Am I getting Module has no attribute error when adding "as"

I have a directory module where I have a python file tools.py

I need to import tools.py from the parent directory of module .

Everything works fine when I specify import module.tools .

However import module.tools as tools doesn't work. And I get an error : Module module has no attribute tools

Instead of using as , use from module import tools . This will import only tools from module .

from module import tools

If you want to rename tools into something shorter, you can do that later in the code.

t = tools

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