I have this interactive session:
>>> str = '192.168.1.1'
>>> str = str.replace('.','\.')
>>> str
'192\\.168\\.1\\.1'
I want the out put to be: 192\.168\.1\.1 instead of 192\\.168\\.1\\.1
How can I achieve this? Why is it behaving this way?
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.
Use
print strinstead ofstr:Your string is the one you expect it to be, but when you just dump the object, python is showing it to you in a form you could use to assign to another string – that means escaping the
\characters.