I have three files, base.py, read_a_file.py, and file_to_be_read.txt.
read_a_file.py contains the function read_file which opens
file_to_be_read.txt to be read. base.py imports read_a_file.py and calls the read_file function. I also have the following file structure:
-directory
-base.py
-read_a_file.py
-file_to_be_read.txt
The problem is that when I run base.py, I receive a FileNotFound error since the working directory is located at root/directory/ rather than at the root. I tried sys.path.append(root) but that didn't seem to work. Any help would be appreciated!
Here's the full traceback:
Error
Traceback (most recent call last):
File "C:\Users\agctute\PycharmProjects\sapaigenealg\myAI\tests\aitests.py", line 26, in test_AI
self.ai = AI(player=Player())
File "C:\Users\agctute\PycharmProjects\sapaigenealg\myAI\playerai.py", line 24, in __init__
self.tier_list = read_tier_list()
File "C:\Users\agctute\PycharmProjects\sapaigenealg\myAI\stat_comparison.py", line 47, in read_tier_list
with open('stat_tier_list.txt', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'stat_tier_list.txt'
sys.pathonly helps with importing python modules, not with regular files.