1

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  
                    ...  

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')

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.