0

I have a django model with a Charfield that contains the unicode escaped string "\\t". What is the easiest way to convert this to a real tab (as in str("\t"))?

Tadeck
  • 132,510
  • 28
  • 152
  • 198
RickyA
  • 15,465
  • 5
  • 71
  • 95

1 Answers1

2

Found the answer:

"\\t".decode("string_escape")

as described here in the comments

In Python3 syntax:

In [5]: b'\\t'.decode("unicode_escape")
Out[5]: '\t'
rahlf23
  • 8,869
  • 4
  • 24
  • 54
RickyA
  • 15,465
  • 5
  • 71
  • 95
  • This may be needless. Where did this data originate? You have have done a `repr()`, `unicode()` or `str()` that was not needed. – S.Lott Jan 04 '12 at 18:06
  • This data comes from a postgresql db that does this cast for me on a character field. I have no control over that, so I need this. – RickyA Nov 19 '12 at 09:16