How to specify File Path / Location?

Hello!
I’m working on my Discord bot and it’s written in Python. It works fine but I want to add json file to store some data there. I don’t know how would I specify the file.

In youtube, they just use paths, given by Windows (since they are on their PC), but how to do it on Glitch?
Tried importing os and then
os.chdir(r"levels_data.json") but it says that it cannot find that file. …

Hi @Wizertex,

Thanks for reaching out!

Where in the file tree does your json file exist?
Is it at the root? Or is it in a folder?

Hi @Wizertex

The path defaults to the current directory, which is “.”, or you can make it relative to the project’s root directory, which is “/app”. Here are some examples

file = open("levels_data.json", "r")
print file.read()
file.close()

file = open("./levels_data.json", "r")
print file.read()
file.close()

file = open("/app/levels_data.json", "r")
print file.read()
file.close()

file = open("/app/levels_folder/levels_data.json", "r")
print file.read()
file.close()

It’s next to the bot.py file.