So I have this Python project in PyCharm on MacOS and I moved the .py files into a folder.
This was my folder structure:
project/input/15_example.txt
project/aoc15.py
And I refactored it by moving aoc15.py up into a solutions folder
project/input/15_example.txt
project/solutions/aoc15.py
Now some of the .py files that have been moved are still able to reach their input files, but some are not. It does seem that .py files that don't import anything more often keep working, but also that is not consistent.
File that stopped working after refactor (aoc15.py):
from pprint import pp
lines = [*map(list,open('../input/15_example.txt').read().splitlines())]
pp(lines)
# FileNotFoundError: [Errno 2] No such file or directory: '../input/15_example.txt'
example file that does work (aoc08.py):
from pprint import pp
segs = [[seg.split(' ') for seg in line.split(" | ")] for line in open('../input/08_input.txt').read().splitlines()]
numbers = {}
for i, line in enumerate(segs):
for j, out in enumerate(line[1]):
if len(out) == 2: numbers[i,j] = '1'
pp(len(numbers))
I'm running my code from PyCharm, if I run it from the terminal they do work. It's running each file from it's own location, as you can see in this full error message (slightly editted for privacy)
/usr/local/bin/python3.9 ~/project/solutions/aoc15.py
Traceback (most recent call last):
File "~/project/solutions/aoc15.py", line 4, in <module>
lines = [*map(list,open('../input/15_example.txt').read().splitlines())]
FileNotFoundError: [Errno 2] No such file or directory: '../input/15_example.txt'
What could be the problem?