0

I am trying to import test.py from within main.py how would I be able to do that? Both main.py and test.py and the data.json is allocated within the application folder. The test.py file is within the app folder. I am trying to open and read the data.json file from test.py. But it is giving me the error FileNotFoundError: [Errno 2] No such file or directory: 'data.json'. how would I be able to read and print the data.json file?

Directories:

application folder
├── appFolder
│   ├──test.py
│   ├──data.json
│   
└── main.py

Code within Main.py

from appFolder import test

Code within test.py

import os
import json

TEST_FILENAME = os.path.join(os.path.dirname(__file__), 'MomentumStrats.json')
data = json.load(TEST_FILENAME)
print(data)

Inside data.json:

{
  "states": [
    {
      "name": "Alabama",
      "abbreviation": "AL",
      "area_codes": ["205", "251", "256", "334", "938"]
    }
}
tony selcuk
  • 709
  • 3
  • 11

0 Answers0