1

Is there a way to take a raw string/literal string in python and interpret it as a regular string. For example.

>>> a = r'un\x00'
>>> len(a)
6

What can I do to 'a' to make len(a) = 3

user700048
  • 119
  • 1
  • 3
  • 9
  • 1
    Why did you write a raw string literal if you wanted a regular string literal? – user2357112 Jan 17 '18 at 22:38
  • 2
    This is a perfect example of the kind of thing our duplicate system is meant for -- finding a case where we already have a question answered, but with a completely different description / set of search terms. – Charles Duffy Jan 17 '18 at 22:45
  • 2
    On the linked duplicate, I prefer the solutions that use `ast.literal_eval`. A one-liner might be like `import ast; b = ast.literal_eval("'''%s'''" % a)`. Quoting might get a bit tricky, but the use of the triple quotes around the string helps. – kindall Jan 17 '18 at 22:48

0 Answers0