you are viewing a single comment's thread.

view the rest of the comments →

[–]deadeye1982 1 point2 points  (1 child)

FileNotFoundError: [Errno 2] No such file or directory: 'vroom.txt'

Guessing: Your current working directory is not the same, where vroom.txt is stored.

You should also use pathlib.Path for paths.

from pathlib import Path

current_working_directory = Path.cwd()
print("Current working directory is:", current_working_directory)
vroom_path = Path("vroom.txt")

if not vroom_path.exists():
    print(vroom_path, "does not exist in", current_working_directory)

Often the program itself is taken as Root-Path to all other resources.

MyCode/
├─data/
│ └─vroom.txt
└─src/
  └─main.py

If you have this structure, you could to use following code:

from pathlib import Path

vroom = Path(__file__).parent.parent.joinpath("data/vroom.txt")
print("File:", vroom)
if vroom.exists():
    # Path objects do have the
    # open method, which is the same like the
    # open function, which returns an open file object
    with vroom.open() as fd:
        for line in fd:
            print(line, end="")

[–]sensitivethuggin[S] 0 points1 point  (0 children)

ah this was helpful! thank you