Last active
January 21, 2017 21:37
-
-
Save lnrsoft/9ee0bec339e4aaa88b27 to your computer and use it in GitHub Desktop.
Determinate the absolute path of a file in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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