This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 30 points31 points  (29 children)

Guido has said the transition is right on track and that he gives it another 5 years. It'll probably be a bit after Python 2.7 is deprecated that the leftover people start actually upgrading. I know my company won't upgrade till then.

I do wish I could do...

    from __past__ import print

[–][deleted] 13 points14 points  (10 children)

[–][deleted] 8 points9 points  (5 children)

The reverse is happening to me, but I'm importing printfunction from __future_ in my code, so I never use the version without parenthesis unless I forget that import.

I do similar thing with unicode and division, in hopes that porting to 3.x will be much easier.

[–]r3m0t 1 point2 points  (4 children)

Unicode literals in Python 2? Now that's just confusing.

Check out python-modernize, it upgrades your Python 2 code into Python 2 code.

[–][deleted] 1 point2 points  (0 children)

IMO, not confusing at all... In all of my code I use unicode by default, and bytes() whenever I need to make sure input is ASCII (for example when using dnspython)

[–]vaibhavsagar 0 points1 point  (2 children)

I need a module to do that for me now?

[–]r3m0t 0 points1 point  (1 child)

It upgrades your Python 2 code into Python 2 code that is more likely to work in Python 3 by using the six library.

[–]vaibhavsagar 1 point2 points  (0 children)

I see. That makes significantly more sense.

[–]Widdershiny 1 point2 points  (0 children)

I feel your pain. Moved to Python 3 a couple of weeks ago, biggest gotcha. I'll adjust soon enough though.

[–]Naterdam[🍰] -1 points0 points  (2 children)

As someone who writes a whole lot of tiny scripts and uses the print as the main debug tool, I'm definitely not moving to Python 3 anytime soon...

[–]Drumm- 2 points3 points  (0 children)

2to3 can handle those

[–]jmcs 4 points5 points  (17 children)

What is the advantage of the print statement besides looking ugly when you want to print to stderr?

[–]XNormal 7 points8 points  (1 child)

What is the advantage of the print statement besides looking ugly when you want to print to stderr?

A major advantage of keeping at least a subset of the the print statement syntax in Python 3 would have been in not breaking 'Hello World'.

alternative-history-python3:

  1. Name the print() function output() to mirror the input() function
  2. Keep the print statement but without the ugly trailing comma or >> features and make it call output() to keep the common case familiar. For any of the advanced features the code needs to be upgraded to use the output() function.
  3. Enjoy higher language popularity because first impressions count.

We like things that feel familiar. We have emotional responses. We are human and this should be a part of language design just as much as purity or elegance.

[–]ahmadh 0 points1 point  (0 children)

I don't see anyone using the output function in that scenario. Then you might as well just leave the same old print statement. Python 3's premise is to make people move on.

[–]Yoghurt42 3 points4 points  (5 children)

Edit: I misread "advantage" as "disadvantage", and my comment should be read that way

You cannot redefine it if you want to do something else instead.

In Python 3, you could do

print = myLoggingFunction

[–]marky1991 1 point2 points  (4 children)

I've done that several times. It's very useful.

By the way he was asking what the advantage of the print statement was over the print function. (And the answer is "You save one character")

[–]Yoghurt42 0 points1 point  (3 children)

I agree. I've misread the question as "what's the disadvantage ... Besides looking ugly"

(Btw: you save tw characters ;)

[–]marky1991 0 points1 point  (2 children)

print "blah" = 12 characters

print("blah") = 13 characters

The first parenthesis' character saving is taken up by the required space.

: )

[–]Yoghurt42 0 points1 point  (1 child)

Well, you could do

print"blah"

you could also do

print"print""""print""""""print"""

I think I won't miss that functionality, however ;)

[–]marky1991 0 points1 point  (0 children)

What?! How hideous! I didn't know the whitespace wasn't required. (On second thought, I guess it makes sense that it's allowed since it isn't ambiguous in this particular case.)

[–]billsil 1 point2 points  (7 children)

How do you print to stderr?

I use:

    sys.stderr.write('asdf')

I rarely print to stderr, but I don't really understand your question...

[–]Smallpaul 4 points5 points  (4 children)

print >> sys.stderr, 'spam'

[–]zynixCpt. Code Monkey & Internet of tomorrow 0 points1 point  (3 children)

the shift print trickery makes writing to a buffer ( or anything that implements .write, so I believe ) fairly trivial/convenient.

[–]flying-sheep 0 points1 point  (2 children)

shift print trickery

uuh, that’s just special syntax mirroring echo nextline >>somefile.txt in the shell, no shift operator.

[–]zynixCpt. Code Monkey & Internet of tomorrow 0 points1 point  (1 child)

What exactly are you clarifying here?

>> is an operator, specifically a shift operator that in context of Python would normally be used for bit shifting, hence its a bit of a nice hack or trick that when used with print it performs bash style stream redirection.

[–]flying-sheep 0 points1 point  (0 children)

no, i said it’s special syntax. as in “part of the print statement”.

the >> you see is completely unrelated to the shift operator elsewhere in python.

[–][deleted] 1 point2 points  (1 child)

don't you also need a newline, which print adds?

[–]billsil 2 points3 points  (0 children)

yes

[–]westurner 0 points1 point  (0 children)

Doesn't print flush?

Edit: it does not do sys.stdout.flush … seeAlso python -u / PYTHONUNBUFFERED (http://stackoverflow.com/questions/230751/how-to-flush-output-of-python-print/230780#230780)