The following code:
key = open("C:\Scripts\private.ppk",'rb').read()
reads the file and assigns its data to the var key.
For a reason, backslashes are multiplied in the process. How can I make sure they don’t get multiplied?
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.
You … don’t. They are escaped when they are read in so that they will process properly when they are written out / used. If you’re declaring strings and don’t want to double up the back slashes you can use raw strings
r'c:\myfile.txt', but that doesn’t really apply to the contents of a file you’re reading in.As you can see, the extra slashes are stored internally, but when you use the value in a print statement (write a file, test for values, etc.) they’re evaluated properly.