[Python 2.6] print_function and unicode_literals cannot be used atthe same time?

Discussion in 'Python' started by ÖܼÃÊÇĸÀÏÊó, Oct 26, 2008.

  1. Any ideas?

    Code 1:

    from __future__ import print_function, unicode_literals
    import sys
    print(type('HELLO, WORLD!'), file=sys.stderr)

    Result 1:

    <type 'str'>

    Code 2:

    from __future__ import unicode_literals, print_function
    import sys
    print(type('HELLO, WORLD!'), file=sys.stderr)

    Result 2:

    File "tmp.py", line 3
    print(type(''), file=sys.stderr)
    ^
    SyntaxError: invalid syntax

    Code 3:

    from __future__ import unicode_literals, print_function
    import sys
    print >> sys.stderr, type('HELLO, WORLD!')

    Result 3:

    <type 'unicode'>
     
    ÖܼÃÊÇĸÀÏÊó, Oct 26, 2008
    #1
    1. Advertising

  2. Re: [Python 2.6] print_function and unicode_literals cannot be usedat the same time?

    En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <>
    escribió:

    > ?????? wrote:
    >> Any ideas?
    >> Code 1:
    >> from __future__ import print_function, unicode_literals
    >> import sys
    >> print(type('HELLO, WORLD!'), file=sys.stderr)

    >
    > You have to do each future import in a separate line:
    >
    > >>> from __future__ import unicode_literals
    > >>> from __future__ import print_function
    > >>> print(type(""), file=sys.stderr)

    > <type 'unicode'>


    That's a bug, isn't it? The language reference explicitely allows it:
    http://docs.python.org/reference/simple_stmts.html#future-statements

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 27, 2008
    #2
    1. Advertising

  3. ÖܼÃÊÇĸÀÏÊó

    Terry Reedy Guest

    Re: [Python 2.6] print_function and unicode_literals cannot be usedat the same time?

    Gabriel Genellina wrote:
    > En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <>
    > escribió:
    >
    >> ?????? wrote:
    >>> Any ideas?
    >>> Code 1:
    >>> from __future__ import print_function, unicode_literals
    >>> import sys
    >>> print(type('HELLO, WORLD!'), file=sys.stderr)

    >>
    >> You have to do each future import in a separate line:
    >>
    >> >>> from __future__ import unicode_literals
    >> >>> from __future__ import print_function
    >> >>> print(type(""), file=sys.stderr)

    >> <type 'unicode'>

    >
    > That's a bug, isn't it? The language reference explicitely allows it:
    > http://docs.python.org/reference/simple_stmts.html#future-statements


    Yes, and Benjamin Peterson already submitted a patch because of this thread.
    http://bugs.python.org/issue4209
     
    Terry Reedy, Oct 27, 2008
    #3
  4. ÖܼÃÊÇĸÀÏÊó

    Benjamin Guest

    Re: print_function and unicode_literals cannot be used at the sametime?

    On Oct 27, 1:00 pm, Terry Reedy <> wrote:
    > Gabriel Genellina wrote:
    > > En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <>
    > > escribió:

    >
    > >> ?????? wrote:
    > >>> Any ideas?
    > >>>  Code 1:
    > >>>  from __future__ import print_function, unicode_literals
    > >>> import sys
    > >>> print(type('HELLO, WORLD!'), file=sys.stderr)

    >
    > >> You have to do each future import in a separate line:

    >
    > >>  >>> from __future__ import unicode_literals
    > >>  >>> from __future__ import print_function
    > >>  >>> print(type(""), file=sys.stderr)
    > >> <type 'unicode'>

    >
    > > That's a bug, isn't it? The language reference explicitely allows it:
    > >http://docs.python.org/reference/simple_stmts.html#future-statements

    >
    > Yes, and Benjamin Peterson already submitted a patch because of this thread.http://bugs.python.org/issue4209


    It will be fixed in 2.6.1.
     
    Benjamin, Oct 29, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page