Py3.3 unicode literal and input()
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Jun 25 08:08:38 EDT 2012
On Mon, 25 Jun 2012 04:17:00 -0700, jmfauth wrote:
> Mea culpa. I had not my head on my shoulders. Inputing if working fine,
> it returns "text" correctly.
>
> However, and this is something different, I'm a little bit surprised,
> input() does not handle escaped characters (\u, \U).
No, it is not different, it is exactly the same. input always returns the
exact characters you type.
If you type a b c space d, input returns "abc d".
If you type a b c backslash u, input returns "abc\u".
input does not treat the text as anything special. If you want to treat
the text "1234" as an int, you have to convert it into an int using the
int() function. If you want to treat the text as a list, you have to
parse it as a list. If you want to treat it as Python source code, you
have to parse it as Python source code. And if you want to treat it as a
Python string literal format using escape characters, you have to parse
it as Python string literal format.
--
Steven
More information about the Python-list
mailing list