Py3.3 unicode literal and input()

jmfauth wxjmfauth at gmail.com
Mon Jun 18 05:30:50 EDT 2012


On 18 juin, 10:28, Benjamin Kaplan <benjamin.kap... at case.edu> wrote:
> On Mon, Jun 18, 2012 at 1:19 AM, jmfauth <wxjmfa... at gmail.com> wrote:
> > What is input() supposed to return?
>
> >>>> u'a' == 'a'
> > True
>
> >>>> r1 = input(':')
> > :a
> >>>> r2 = input(':')
> > :u'a'
> >>>> r1 == r2
> > False
> >>>> type(r1), len(r1)
> > (<class 'str'>, 1)
> >>>> type(r2), len(r2)
> > (<class 'str'>, 4)
>
> > ---
>
> > sys.argv?
>
> > jmf
>
> Python 3 made several backwards-incompatible changes over Python 2.
> First of all, input() in Python 3 is equivalent to raw_input() in
> Python 2. It always returns a string. If you want the equivalent of
> Python 2's input(), eval the result. Second, Python 3 is now unicode
> by default. The "str" class is a unicode string. There is a separate
> bytes class, denoted by b"", for byte strings. The u prefix is only
> there to make it easier to port a codebase from Python 2 to Python 3.
> It doesn't actually do anything.


It does. I shew it!

Related:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3aefd602507d2fbe#

http://mail.python.org/pipermail/python-dev/2012-June/120341.html

jmf



More information about the Python-list mailing list