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