Where to put a configuration file in Python?

前端 未结 7 1782
孤独总比滥情好
孤独总比滥情好 2020-12-22 17:52

In development mode, I have the following directory tree :

| my_project/
| setup.py
| my_project/
    | __init__.py
    | main.py
    | conf/
        | mypro         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 18:18

    Another option is to keep all the .cfg and .ini files in the home directory, like 'boto' does.

    import os.path
    config_file = os.path.join(os.path.expanduser("~"), '.myproject')
    

提交回复
热议问题