ip-address

How to split an SSH address + path?

核能气质少年 提交于 2020-12-12 05:22:56
问题 A Python 3 function receives an SSH address like user@132.243.32.14:/random/file/path . I want to access this file with the paramiko lib, which needs the username, IP address, and file path separately. How can I split this address into these 3 parts, knowing that the input will sometimes omit the username ? 回答1: str.partition and rpartition will do what you want: def ssh_splitter(ssh_connect_string): user_host, _, path = ssh_connect_string.partition(':') user, _, host = user_host.rpartition('