How to import the class within the same directory or sub directory?

后端 未结 13 1124
醉梦人生
醉梦人生 2020-11-22 06:34

I have a directory that stores all the .py files.

bin/
   main.py
   user.py # where class User resides
   dir.py # where class Dir resides
         


        
13条回答
  •  醉梦人生
    2020-11-22 06:52

    I just learned (thanks to martineau's comment) that, in order to import classes from files within the same directory, you would now write in Python 3:

    from .user import User
    from .dir import Dir
    

提交回复
热议问题