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?

mpen
  • 272,448
  • 266
  • 850
  • 1,236
gokul
  • 15
  • 4

1 Answers1

1

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

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

jmduke
  • 1,657
  • 1
  • 13
  • 11
  • if i use os.path.abspath("file.txt") I got only D:\\file.txt. not full path – gokul Jul 24 '14 at 21:02
  • 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. – jmduke Jul 24 '14 at 21:06