Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Last active January 21, 2017 21:37
Show Gist options
  • Save lnrsoft/9ee0bec339e4aaa88b27 to your computer and use it in GitHub Desktop.
Save lnrsoft/9ee0bec339e4aaa88b27 to your computer and use it in GitHub Desktop.
Determinate the absolute path of a file in Python
import os
def getcurrentloc(fileName):
isfile = os.path.isfile(fileName)
notfound = (str(fileName) + " does not exist")
if isfile: # if (True) file exist return the path
return os.path.abspath(fileName)
else:
print notfound
file_Name = "whatever.txt"
myfile = getcurrentloc(file_Name)
print(myfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment