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
  • 125,377
  • 26
  • 148
  • 197
RickyA
  • 14,690
  • 5
  • 65
  • 93

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,613
  • 3
  • 19
  • 49
RickyA
  • 14,690
  • 5
  • 65
  • 93
  • 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