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.
精彩评论