I'm having a strange issue. I'm just trying to do a basic show directory contents for relative path.
Created a test directory on the desktop
test directory contents
test.py
test1 -- folder
sample.txt
contents of test.py
import os
dataDir = "test1"
for file in os.listdir("/Users/username/Desktop/test"):
print(file)
Summary - absolute path
- works - in visual studio code
- works - macOS terminal python3 /Users/username/Desktop/test/test.py
however when use the variable I get an error:
contents of test.py
import os
dataDir = "test1"
for file in os.listdir(dataDir):
print(file)
Summary - relative path
- works - in visual studio code
- ERROR - macOS terminal python3 /Users/username/Desktop/test/test.py
Traceback (most recent call last): File "/Users/username/Desktop/test/test.py", line 4, in for file in os.listdir(dataDir): FileNotFoundError: [Errno 2] No such file or directory: 'test1'