Python - Get path of root project structure

后端 未结 16 1829
陌清茗
陌清茗 2020-12-04 08:03

I\'ve got a python project with a configuration file in the project root. The configuration file needs to be accessed in a few different files throughout the project.

16条回答
  •  悲&欢浪女
    2020-12-04 08:38

    All the previous solutions seem to be overly complicated for what I think you need, and often didn't work for me. The following one-line command does what you want:

    import os
    ROOT_DIR = os.path.abspath(os.curdir)
    

提交回复
热议问题