Ask coding questions

← Back to all posts
How do I find file directory of replit?
UnknownDBD (0)

I'm trying to open a json file with python using os.chdir() function.

Comments
hotnewtop
Geocube101 (645)

If you want to open a file then use the open function
It returns a file handle to read (or write) files. Read the contents and then pass it through a json parser

with open("path/to/file.json", "r") as f:
  contents = f.read()
  # Do something with contents (like parse it into JSON)

os.chdir changes the current working directory and as such I don't think it can be used to open a file