1import os
2# you have to be in the same directory as the file
3file = 'myfile.txt'
4# or also
5file = 'directory/to/myfile.txt'
6
7path = os.path.abspath(file)
8
1>>> import os
2>>> os.path.abspath("mydir/myfile.txt")
3'C:/example/cwd/mydir/myfile.txt'
4
1from pathlib import Path
2relative = Path("my_path")
3absolute = relative.asolute()
1>>> f = open('/Users/Desktop/febROSTER2012.xls')
2>>> f.name
3'/Users/Desktop/febROSTER2012.xls'