\" is converted to \\" while saving the string to dictionary in python -


i need save string having " ' " in dictionary along \" instead of '.

the example shown below. code:

 ss = "{'username': {'suffix': none}"    print ss    print ss.replace("'", '\\"')    temp = dict()    temp["key"] = ss.replace("'", '\\"')    print str(temp) 

output:

{'username': {'suffix': none} {\"username\": {\"suffix\": none} {'key': '{\\"username\\": {\\"suffix\\": none}'} 

please let me know 1 have solution or alternative this.

you looking @ repr() representation of string. normal. string representation uses escape codes non-printable characters or requires escaping.

python containers show contents, when printed, string representations debugging purposes. resulting string representation re-usable string literal, can paste right python , it'll produce same value.

print individual values of want see output unescaped:

print temp["key"] 

and if feel inclined, compare repr() result of string:

print repr(temp["key"]) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -