How to organize a Python Project?

后端 未结 8 1983
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 16:35

I\'m new to Python and I\'m starting a mini Project, but I have some doubts on how to organize the folders in the \"Python Way\".

I\'m using PyDev in my

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 16:50

    From a file system perspective, a module is a file ending with .py and a package is a folder containing modules and (nested) packages again. Python recognizes a folder as a package if it contains a __init__.py file.

    A file structure like that

    some/
        __init__.py
        foofoo.py
        thing/
            __init__.py
            barbar.py
    

    defines the package some, which has a module foofoo and a nested package thing, which again has a module barbar. However, when using packages and modules, you don't really distinguish these two types:

    import some
    
    some.dothis() # dothis is defined in 'some/__init__.py'
    
    import some.foofoo # <- module
    import some.thing # <- package
    

    Please follow PEP8 when selecting naming your packages/modules (i.e. use lower-case names).

提交回复
热议问题