This is my project structure:
main
-/data/data.json
-/a/b/c.py
main.py
data folder an a folder are in main folder which is the root of my project. I need to read data.json from c.py in python3 what would be my string in open()?
file = open('./data/data.json')
this works in windows but not linux
Up two folders and then in data/data.json
:
with open('../../data/data.json') as f:
...
If you are on Windows, swap slashes with backslashes .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.