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

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

    Python 3


    Same directory.

    import file:log.py

    import class: SampleApp().

    import log
    if __name__ == "__main__":
        app = log.SampleApp()
        app.mainloop()
    

    or

    directory is basic.

    import in file: log.py.

    import class: SampleApp().

    from basic import log
    if __name__ == "__main__":
        app = log.SampleApp()
        app.mainloop()
    
    0 讨论(0)
提交回复
热议问题