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

后端 未结 13 1131
醉梦人生
醉梦人生 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 07:02

    You can import the module and have access through its name if you don't want to mix functions and classes with yours

    import util # imports util.py
    
    util.clean()
    util.setup(4)
    

    or you can import the functions and classes to your code

    from util import clean, setup
    clean()
    setup(4)
    

    you can use wildchar * to import everything in that module to your code

    from util import *
    clean()
    setup(4)
    

提交回复
热议问题