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")
)?
Asked
Active
Viewed 1,955 times
0
-
1It **is** a tab. Where are you seeing `\t`? – S.Lott Jan 04 '12 at 16:34
-
Whoa, one of my backslashes disappeared. Updated question. – RickyA Jan 04 '12 at 16:40
-
Where are you seeing `\\t`? Is this in the database? In a log? On the web page? Where are you seeing this? – S.Lott Jan 04 '12 at 16:41
-
in the debug value for the model field: "unicode: \\t" – RickyA Jan 04 '12 at 17:08
-
"debug value"? It's a model field? Where did this data come from? How did this data get into the model? Please provide some information on where this value originated. – S.Lott Jan 04 '12 at 17:54
1 Answers
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'
-
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