InfinteScroll
InfinteScroll

Reputation: 684

python: open a json file in a different directory?

Here's my code:

import json    
with open("json.items") as json_file:
        json_data = json.load(json_file)

It works fine when I move the json file into the same directory. However, I'm trying to get the json file from a different directory. How would I do that? This is what I have tried and its not working:

with open("/lowerfolder/json.items") as json_file:

Any help? Thanks

Upvotes: 4

Views: 26199

Answers (1)

mhlester
mhlester

Reputation: 23211

Depending on your platform, starting a path with / means absolute path from the root

Meaning a relative path should be open("lowerfolder/json.items") without the /

Upvotes: 8

Related Questions