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.py105 chars7 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