How can I extract the hostname from: hostname:/file_name ? For example in ngs.pradhi.com:/upload, I want to extract ngs.pradhi.com from it and test it via ssh.connect.
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The string in your example isn’t a URL, so you won’t be able to use the standard URL module (
urlparse) to parse it. Here is how you can do it by hand:For SSH, take a look at
paramiko.