find the path of a json file in python

To find the path of a JSON file in Python, you can use the os module to get the current directory (os.getcwd()) and then append the file name to create the file path. Here's an example:

main.py
import os

file_name = "example.json"
file_path = os.path.join(os.getcwd(), file_name)

print(file_path)
105 chars
7 lines

In this example, os.path.join() is used to join the current directory path (os.getcwd()) and the file name (example.json) to create the file path.

You can then use this file path to read or write to the JSON file using json.load() or json.dump() respectively.

gistlibby LogSnag