Python Path as a String
I Am Specifying a Relative File Path Using Jacaro's Path Module. How Can I Get the Absolute Path from This Variable as a String? Import Path # from Path =...
I am specifying a relative file path using jacaro's path module.
How can I get the absolute path from this variable as a string?
import path # From
path = path.path('~/folder/')
relative_filename = path.joinpath('foo')
# how can I get the absolute path of as a string?
absolute_path = ???
fd = open(absolute_path)
1 Answer
filename has a method called abspath that returns an object with the absolute path. You can cast that to a string.
...
folder_path = path('~/folder/')
filename = path.joinpath('foo')
f = sftp.open(str(filename), 'r')