0

Take a look at the following example:

In [1]: u'{u\'cname\': u"A\'B"}'
Out[1]: u'{u\'cname\': u"A\'B"}'

In [2]: u'{u\'cname\': uA\'B}'
Out[2]: u"{u'cname': uA'B}"

As you can see, the first string has additional pair of " in it, and it looks like this change is causing the entire escape logic to be altered - in the second example, there are no backslashed printed, while in the first one there are.

Why does this happen?

Thanks!

Tal
  • 398
  • 4
  • 19
  • 1
    The top one has `"` _inside_ it (followed by `'`), and the bottom one has `'` inside it (followed by `"`). That's different content. A string containing `"` is different from a string containing `'` because they are different characters. – khelwood Jan 16 '19 at 14:23
  • @khelwood They are exactly the same. There is a full symmetry between the two strings. – Tal Jan 16 '19 at 14:25
  • They're not the same. `"\""` is a different string from `'\''` because they have a different character inside them. – khelwood Jan 16 '19 at 14:25
  • 1
    `'` inside a `'` delimited string must be escaped, but `"` inside `'` does not (and vice versa). The backslash therefore has a meaning or has none. Note that Python formats the string to be `'` delimited either way, and uses backlashes appropriately. – deceze Jan 16 '19 at 14:26
  • @khelwood, deceze, The question I asked was not accurate. I rephrased the question. Sorry about the confusion. – Tal Jan 16 '19 at 14:37

0 Answers0