News for hackers. Stuff that matters.
Re:Python 2.x vs 3.x use survey by dec0dedab0de on Tuesday December 31, 2013 @09:56AM (#6990700)
Missing a question. "Would you switch to python 3 if they brought back the print statement"

Edit: I really just like the statement for the interpreter, and IPython Notebook. To me the statement syntax feels less like programming, and more like using a computer.

Re:Python 2.x vs 3.x use survey by dded on Tuesday December 31, 2013 @10:26AM (#6990883)
Personally, I prefer function. I can understand that others have a different preference; what I find surprising is the number of people who seem to care so much about this. Nevertheless, it is very evident that you are not alone.
Re:Python 2.x vs 3.x use survey by bcj on Tuesday December 31, 2013 @10:34AM (#6990925)
I prefer it as well. Being able to do things like throw

    print(<SOMETHING I'M TRYING TO DEBUG>) or
into a lambda has been useful on multiple occasions.
Re:Python 2.x vs 3.x use survey by Kliment on Tuesday December 31, 2013 @10:18AM (#6990831)
I don't mind the print statement/function thing but I am bothered by the pain when dealing with byte strings. I use Python to talk to hardware that doesn't speak unicode, the contortions I have to go through to get byte strings to behave correctly on py3 are frustrating. I have no problem with the default string being unicode, but why can't byte strings be implemented like the unicode strings were done on py2.x?
Re:Python 2.x vs 3.x use survey by viraptor on Tuesday December 31, 2013 @10:21AM (#6990856)
What's the specific issue? I find it solves loads of issues before where you could mix bytes and unicode by accident. Not only are they more explicit, I find the fact that `b'\0'[0] == 0` - way better when working with actual bytes.
Re:Python 2.x vs 3.x use survey by Kliment on Tuesday December 31, 2013 @10:28AM (#6990888)
The inability to use string manipulation functions on bytestrings without converting them to unicode and back for each operation.
Re:Python 2.x vs 3.x use survey by viraptor on Tuesday December 31, 2013 @10:35AM (#6990926)
What do you mean by "string manipulation"? bytes are not text strings. If you actually mean text operations, then converting them is something you should also do in py2.

Edit: now that I thought about it - since you're able to decode the bytes you're using, it means you are operating on text - why not convert it then?

Re:Python 2.x vs 3.x use survey by Kliment on Tuesday December 31, 2013 @02:11PM (#6992246)
See http://bugs.python.org/issue3982 that's linked elsewhere in these comments for the kind of things that don't work on bytestrings
Re:Python 2.x vs 3.x use survey by viraptor on Tuesday December 31, 2013 @08:30PM (#6993749)
I read it all, and to be honest I think I agree the most with http://bugs.python.org/issue3982#msg180441 (.format may be making some things simpler, but it goes against the idea of well separated bytes -vs- text)

But really, I just don't like how http/ftp/similar protocols were designed in the first place. They're mixing binary and text in the same stream. That's ugly and when you have strict rules about text encoding in your language, the implementation also turns out ugly - what a surprise :)

Re:Python 2.x vs 3.x use survey by Borogove on Tuesday December 31, 2013 @04:09PM (#6992854)
As many comments in that thread point out, byte arrays are not strings, and casually conflating or implicitly converting the two is terrible mental hygiene.

Explicit is better than implicit.

Re:Python 2.x vs 3.x use survey by viraptor on Tuesday December 31, 2013 @10:00AM (#6990722)
Is there some story behind it? It looks like the smallest issue out of the whole migration. (especially with from __future__ import print_function)
Re:Python 2.x vs 3.x use survey by sp332 on Tuesday December 31, 2013 @10:03AM (#6990744)
I think people would prefer "from __past__ import print_statement" in 3.x.
Re:Python 2.x vs 3.x use survey by viraptor on Tuesday December 31, 2013 @10:10AM (#6990796)
That's why I'm asking really - not only those two would be pretty much equivalent, there's really nothing that can be expressed with one, but not the other. I mean that's kind of like saying "would you use it if they called the binary snake instead of python3" - what's the reason apart from personal preference for the syntax?
Re:Python 2.x vs 3.x use survey by d0vs on Tuesday December 31, 2013 @10:07AM (#6990775)
Why the hell?
Re:Python 2.x vs 3.x use survey by sp332 on Tuesday December 31, 2013 @10:13AM (#6990809)
Re:Python 2.x vs 3.x use survey by trwired on Tuesday December 31, 2013 @10:34AM (#6990923)
I would hazard a guess that it is because the statement allows for easily adding a `print varname` in your code while debugging.
Re:Python 2.x vs 3.x use survey by randlet on Tuesday December 31, 2013 @10:52AM (#6991040)
It's two extra chars to write print(varname). One if your editor auto-inserts matching parens!
Re:Python 2.x vs 3.x use survey by sp332 on Tuesday December 31, 2013 @10:56AM (#6991067)
Since the space is replaced by the first paren, it's either 0 or 1 more chars :)
Re:Python 2.x vs 3.x use survey by Shish2k on Tuesday December 31, 2013 @12:10PM (#6991497)
Shift-9 is more fiddly to type than space though :P
Re:Python 2.x vs 3.x use survey by dragonwriter on Tuesday December 31, 2013 @11:00AM (#6991101)
print(varname) is one extra keystroke -- and a whole more convenient than a statement when you want to do it in a lambda for debugging.
Re:Python 2.x vs 3.x use survey by wonjohnchoi on Tuesday December 31, 2013 @10:51AM (#6991031)
What is the advantage of python 2 print over python 3 print? I believe that python 3 print can do everything python 2 print can do on the same level of elegancy. Also, python 2 print has a weird trailing-comma syntax. When a trailing comma is added to a print statement, a space is printed when another print statement is used. For example,

print 'hi', # prints hi (no extra space in the end)

print 'hi',; print 'hi' # prints hi hi

I personally dislike this syntax because I don't find this natural. Wouldn't it make more sense to print an extra space after the print statement with trailing comma instead of before the next print statement?

Re:Python 2.x vs 3.x use survey by zephjc on Tuesday December 31, 2013 @11:13AM (#6991196)
no trailing space is a convenient shorthand - print by itself prints with a newline (so it might make sense to have print() vs println()); print + comma omits the newline and waits for the next print statement, so that

    print 'hi',
    do_something()
    print 'there'
and

    print 'hi', 'there'
both yield

    hi there
(Assuming do_something() doesn't call print itself)
Re:Python 2.x vs 3.x use survey by falcolas on Tuesday December 31, 2013 @11:20AM (#6991241)
FWIW:

    pprint = functools.partial(print, end=' ')
    pprint('hi')
    do_something()
    print('there')

    print('hi', 'there', sep=' ')
I appreciate the fine grained control, and the ability to do things like `functools.partial` on it.

    fprint = functools.partial(print, file='/var/log/foo.log')
    fprint("I'm writing to a file!")
    fprint("So am I")
Re:Python 2.x vs 3.x use survey by Fede_V on Tuesday December 31, 2013 @12:00PM (#6991443)
I understand this, but couldn't you simply wrap print itself in a function, and do that in Python 2.7 already? Granted, your method saves you one line and it's more 'natural'.
Re:Python 2.x vs 3.x use survey by falcolas on Tuesday December 31, 2013 @12:39PM (#6991664)
Not really, since the Python 2 version is a keyword, and not a function, you can't simply provide keyword arguments to it. You would instead have to build up a string and eval it. It would have to be something like this (completely untested):

    def print_wrapper(*args, **kwargs)
        outfile = None
        print_stmt = "print "
        if 'file' in kwargs:
            outfile = open(kwargs['file'], 'a')
            print_stmt += '>>outfile '
        print_stmt += ", ".join(*args)
        if 'end' in kwargs and kwargs['end'] == ' ':
            print_stmt += ','
        eval(print_stmt)
        if outfile is not None: outfile.close()
sep and other end values for anything other than ' ' would not be possible.

http://docs.python.org/2.6/reference/simple_stmts.html#the-p...