简体   繁体   中英

Why does this import code work in Visual Studio Code but not IDLE?

File Structure

Main Folder

Program.py

Module_Folder
     MODULE_1.py
     MODULE_2.py
     MODULE_3.py

In "Program.py" I am using the following line to import MODULE_1 into Program.py: "from Module_Folder import MODULE_1 as MODULE_1" This works in visual studio code but not in IDLE. Could someone advise me on what to change for this to work in IDLE?

You should probably add an __init__.py file to your Module_Folder , so Python would know it's a package. You cannot simply import files from folders, if they don't have __init__.py

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