By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
?????? 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'>

Christian

Oct 26 '08 #2

P: n/a
En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <li***@cheimes.de>
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/sim...ure-statements

--
Gabriel Genellina

Oct 27 '08 #3

P: n/a
Gabriel Genellina wrote:
En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <li***@cheimes.de>
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/sim...ure-statements
Yes, and Benjamin Peterson already submitted a patch because of this thread.
http://bugs.python.org/issue4209

Oct 27 '08 #4

P: n/a
On Oct 27, 1:00*pm, Terry Reedy <tjre...@udel.eduwrote:
Gabriel Genellina wrote:
En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <li...@cheimes.de>
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/sim...ure-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.
Oct 29 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.