0

how to find exact path of file in python.? This is very basic. But i am new to python

if my filename is file.txt

 path = "D:\\Utilities\\folder\\python\\model\\file.txt

how to get the exact path by giving only the filename?

1

1 Answer 1

1

Look into the os.path module, specifically abspath(path), which:

return[s] a normalized absolutized version of the pathname path.

Sign up to request clarification or add additional context in comments.

2 Comments

if i use os.path.abspath("file.txt") I got only D:\\file.txt. not full path
At that point you're passing a string to abspath and it's building the path based on your current working directory (presumably D:\`). You need to either run the code in the same directory as file.txt` or be more specific in your relative path.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.