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

后端 未结 13 1119
醉梦人生
醉梦人生 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:48

    Python3

    use

    from .user import User inside dir.py file
    

    and

    use from class.dir import Dir inside main.py
    or from class.usr import User inside main.py
    

    like so

提交回复
热议问题