开发者

Python adding config files to path

开发者 https://www.devze.com 2023-04-09 03:45 出处:网络
I have directory structure like following: analytics //\\\\ conf scriptsrcother /\\/\\/\\ <setup><source>

I have directory structure like following:

           analytics  
       /   /     \   \
    conf script  src  other  
    /  \  /  \   /  \   
   <setup>         <source>  

< setup >:  
       setup.yaml  
       sql.yaml  

< source  >:  
       src/  
           folder A/  
                    s1.py  
                    s2.py  
                    ...  
           folder B/
                    m1.py  
                    m2.py  
                 开发者_StackOverflow   ...  

How can I inclue the setup files in of this structure to the source files in structure without hardcoding the paths

I tried sys.path.append('< path >') but when I try to open the file I see error

>>> import sys
>>> sys.path.append('/Users/user/Documents/work/dw/analytics/conf')
>>> f = open('setup.yaml', 'r')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'setup.yaml'
>>> f = open('setup.yaml', 'r')


open() (and all the other file access functions) don't care about sys.path. It's only used when importing modules.

Create your own variable that contains the path that contains your files, and use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号