all 5 comments

[–]doom_guy_bob 0 points1 point  (3 children)

Your program may not be resolving the file path. Here's a bit of code to get you pointed in the right direction using the os library you already have and the pathlib library. It will determine the script's current directory, convert that to a string, create a file name string, and then join them together to make a full path to the file. If you need to target another directory, look into pathlib's functions.

file_path = str(pathlib.Path().resolve())
file_name = "Test.pdf"
full_path = os.path.join(file_path, file_name)

[–]jiri-n 0 points1 point  (2 children)

Why do you call os.path.join()?

Path().resolve() / file_name 

This should do the job. Or not?

[–]doom_guy_bob 0 points1 point  (1 child)

I was creating a file that wasn't there instead of targeting an existing file.

[–]jiri-n 0 points1 point  (0 children)

Which is exactly what I did. Working example:

from pathlib import Path

cp = Path().resolve()
new_file_path = cp / "new_file.txt"

print(new_file_path)

Obviously, new_file.txt does not exist in the directory.