I use this module
And I have a function that needs a string. I don't find any function which can give me the total path as a string.
from path import *
import paramiko
if __name__ == "__main__":
hostname = 'localhost'
username = '**'
password = '**'
port = 22
transport = paramiko.Transport((hostname, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
path = path('~/folder/')
filename = path.joinpath('foo')
f = sftp.open(filename, 'r') #open needs a string
Do you have an idea?
The Path() object will convert forward slashes into the correct kind of slash for the current operating system.
On Windows, paths are written using backslashes (\) as the separator between folder names. OS X and Linux, however, use the forward slash (/) as their path separator. If you want your programs to work on all operating systems, you will have to write your Python scripts to handle both cases.
the slash / is the directory separator. in every directory there are two directories, namely . ( current directory) and .. ( parent directory) if a path starts with a slash, it means it's the root of the filesystem.
You cannot just put \ in front of any character to escape it. In order to actually print a space, you would have to use '\x20' or you could use '\t' to print a tab.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With