简体   繁体   中英

How can i get rid following situation when importing files in Python 3.7? [on hold]

I had the following folder structure

Folder
    Folder1
       ->File1.py
       ->File2.py
           -> import File1.py
    Folder2
        ->File1.py
        ->File2.py
            -> import File1.py

In this case when I am running File2.py of Folder2 from Folder Directory python importing File1.py from Folder1 instead of Folder2.

Try below line

from . import File1

and make sure you are running File2.py from same directory where it is saved in your computer.

It shouldn't be running or importing another file from a different directory, as python can only import from the same directory (unless adding it the path)

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