0

I am trying to preserve the unicode in dict here is the string looks like:

password = r"abc\3]xyz"
print(password)
output:
abc\3]xyz

But when I use the same variable in dict it's adding an escape character:

id_pass = { "id" : "username", "password" : password }
print(id_pass)
output:
{ u'id' : u'username', u'password' : u'abc\\3]xyz"' }

Expected:
{ u'id' : u'username', u'password' : u'abc\3]xyz"' }

I am not able to figure out a way.

Alec
  • 8,529
  • 8
  • 37
  • 63
Sridhar
  • 27
  • 3

2 Answers2

2

It's not changing the value of your string, it's merely printing its repr() value, which shows the escape value.

brunns
  • 2,689
  • 1
  • 13
  • 24
2

It looks like it's adding an escape character because if you pass it to repr(), which is what is displayed, an escape character is added in the visualization. Nothing is actually being changed.

Alec
  • 8,529
  • 8
  • 37
  • 63