Using AWS Cloud9 for a Python 3.x application. I am trying to open a file (using with open
) in the same directory as the python file, however, it only works if I define the absolute path.
Relative Path
import csv
with open("test.csv", newline='') as f:
reader = csv.reader(f, delimiter=' ', quotechar='|')
for row in reader:
print(', '.join(row))
Error in Terminal
Traceback (most recent call last):
File "/home/ec2-user/environment/test/test.py", line 3, in <module>
with open("test.csv", newline='') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test.csv'
Absolute Path
import csv
with open("/home/ec2-user/environment/test/test.csv", newline='') as f:
reader = csv.reader(f, delimiter=' ', quotechar='|')
for row in reader:
print(', '.join(row))
No Errors