Python 2.x vs. python 3.x

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

wumpus
Posts: 533
Joined: Thu Feb 21, 2008 12:16 am UTC

Python 2.x vs. python 3.x

Postby wumpus » Sat Feb 02, 2013 12:17 am UTC

I fell in love with python 2.x. Everything was intuitive, and did what I meant. The batteries included were nice, if less than reliable (SHA==SHA0, I'm looking at you. Also pickle is too dangerous for rookie programmers).

Much of what I do involves taking binary blobs and stuffing them into swig (C or C++) wrappers. Fine, I'll just use "bytes" since all I want is to have is bytes-in-a-row. No dice. It seemed that "bytes" meant "an intermediate format that can only be converted from unicode to unicode, and don't you dare try to create anything that can be dumped onto disk that isn't the holy unicode.

My duck typing now had a platyupus class thrown in. All was no longer well in python.

So how is it now? Do pythonistas still believe in python3000? Has the old guard given up in disgust and moved off to ruby leaving only those who favor 3.x? Is there any good replacement for the way you could send ascii strings to swig and read them as char?

Derek
Posts: 2179
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Python 2.x vs. python 3.x

Postby Derek » Sat Feb 02, 2013 7:42 am UTC

I cringe everytime I see a print statement that doesn't use parentheses. Yes, I know this is allowed in Python 2 and I do it, but something about Python 2 encourages everyone else to drop the parentheses around print, making otherwise beautiful Python code look ugly.

The fact that standard strings in Python 2 weren't unicode was a glaring omission. In fact, if you're not using unicode strings today, you're doing something horribly, horribly wrong.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Python 2.x vs. python 3.x

Postby EvanED » Sat Feb 02, 2013 4:06 pm UTC

I am somewhat surprised and, to be honest, quite skeptical at your comment about the bytes type having to be Unicode.

I don't deal with binary data... ever, basically, but my own opinion on Python 3 is that it is essentially a uniform improvement over 2 in every change respect with the exception of compatibility. Admittedly this is a biased sample, but the large majority of opinions on the python-list mailing list are also in favor of Python 3 (if realistic about there being times it can't be used).

User avatar
Mat
Posts: 414
Joined: Fri Apr 21, 2006 8:19 pm UTC

Re: Python 2.x vs. python 3.x

Postby Mat » Sat Feb 02, 2013 5:40 pm UTC

I'm not familiar with what you're trying to do, but what's wrong with bytes exactly? Isn't it essentially as the same as regular strings in python2?

Brickmack
Posts: 59
Joined: Wed Sep 01, 2010 1:48 am UTC

Re: Python 2.x vs. python 3.x

Postby Brickmack » Sun Feb 03, 2013 2:56 am UTC

I use python 2.7, 3.x is just annoying without much improvement that I could see.

User avatar
Mat
Posts: 414
Joined: Fri Apr 21, 2006 8:19 pm UTC

Re: Python 2.x vs. python 3.x

Postby Mat » Sun Feb 03, 2013 12:38 pm UTC

Only annoying in that you have to unlearn stuff. Pretty much all the backwards incompatible changes fix stuff that was stupid before:
  • for i in range() is the obvious way to build a loop, but it creates a useless list, so you really want xrange()
  • 'bla' and str() is how you create strings, but unless you are restricting yourself to ascii, you really want u'bla' and unicode()
  • You get shitty old style classes if you don't inherit from object
  • / does both integer and float division, so you have to convert operands to float all the time to get the behaviour you want

User avatar
phlip
Restorer of Worlds
Posts: 7557
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Python 2.x vs. python 3.x

Postby phlip » Mon Feb 04, 2013 4:55 am UTC

wumpus wrote:It seemed that "bytes" meant "an intermediate format that can only be converted from unicode to unicode, and don't you dare try to create anything that can be dumped onto disk that isn't the holy unicode.

I haven't played with interacting with Python/C/C++ interfaces, so I don't know about that much, but "bytes" values absolutely can be dumped to disk and read back exactly as you'd expect:

Code: Select all

Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = open('/tmp/tmp.txt', 'wb')
>>> a.write(b"Test");
4
>>> a.close()
>>> a = open('/tmp/tmp.txt', 'rb')
>>> a.read()
b'Test'
>>> a.close()
The relevant part is that the files are opened in binary mode - if they're opened in text mode (the default) then they'll be read as Unicode strings (you can specify the encoding or let it fall back to the platform default).

I'd be very surprised if the interface for interacting with char* arrays in C from Python3 using bytes is substantially different than doing so in Python2 using str.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Python 2.x vs. python 3.x

Postby EvanED » Mon Feb 04, 2013 6:46 am UTC

Mat wrote:Only annoying in that you have to unlearn stuff. Pretty much all the backwards incompatible changes fix stuff that was stupid before: ...

Not to mention my favorite change:

Code: Select all

~ : python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "zebra" < 7.45
False
>>> ^D

~ : python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "zebra" < 7.45
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < float()

Of course this is still around:

Code: Select all

>>> 1==True
True
>>> 0 == False
True

User avatar
Copper Bezel
Posts: 2426
Joined: Wed Oct 12, 2011 6:35 am UTC
Location: Web exclusive!

Re: Python 2.x vs. python 3.x

Postby Copper Bezel » Wed Feb 06, 2013 7:00 am UTC

Oh, wow, that traceback thing is new to python 3? In the very, very, absurdly little I've played around with python (like, "where is the bathroom" and "my name is ...",) that was the only feature that helped me survive. = /
So much depends upon a red wheel barrow (>= XXII) but it is not going to be installed.

she / her / her

User avatar
phlip
Restorer of Worlds
Posts: 7557
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Python 2.x vs. python 3.x

Postby phlip » Wed Feb 06, 2013 7:24 am UTC

No, the traceback has been around for a while... as long as I've been using Python, at least. What's changed in that snippet is that you used to be able to compare a string and a number with less-than and friends, and you no longer can do so.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Copper Bezel
Posts: 2426
Joined: Wed Oct 12, 2011 6:35 am UTC
Location: Web exclusive!

Re: Python 2.x vs. python 3.x

Postby Copper Bezel » Wed Feb 06, 2013 5:32 pm UTC

Ah, I see. Was worried there. = )
So much depends upon a red wheel barrow (>= XXII) but it is not going to be installed.

she / her / her

User avatar
bug sniper
Posts: 8
Joined: Wed Nov 30, 2011 9:29 am UTC

Re: Python 2.x vs. python 3.x

Postby bug sniper » Tue Apr 23, 2013 7:27 am UTC

Once I get the hang of Python 3, I'm probably going to love the fact that I don't have to think about whether I'm encoding or decoding utf-8 and unicode, or think about the difference between the two.
Carry the black torch! Rouse the idle dead!
-Dungeon Crawl.

User avatar
cemper93
Posts: 209
Joined: Sun Feb 20, 2011 2:35 pm UTC
Location: `pwd`

Re: Python 2.x vs. python 3.x

Postby cemper93 » Mon May 27, 2013 11:48 am UTC

What I don't like about Python 3:

Code: Select all

>>> True = 2
  File "<stdin>", line 1
Syntax error: assignment to keyword

I mean, seriously? Where's the fun?
Oh, and this is absolutely idiotic:

Code: Select all

>>> def f(a, (b, c)):
  File "<stdin>", line 1
    def f(a, (b, c)):
             ^
SyntaxError: invalid syntax

Absolutely a step in the wrong direction. I mean, why remove this cool feature? What were these monkey-brains thinking!?

Other than that, it's probably better, but because pygame and mutagen don't support it yet, I don't either.

xGeovanni
Posts: 36
Joined: Thu Oct 06, 2011 7:03 pm UTC

Re: Python 2.x vs. python 3.x

Postby xGeovanni » Mon Sep 23, 2013 9:05 am UTC

cemper93 wrote:pygame and mutagen don't support it yet


I've been using Pygame with Python 3 for ages now. You can download Pygame for Python 3 here.

User avatar
Mat
Posts: 414
Joined: Fri Apr 21, 2006 8:19 pm UTC

Re: Python 2.x vs. python 3.x

Postby Mat » Mon Sep 23, 2013 9:29 pm UTC

xGeovanni wrote:
cemper93 wrote:pygame and mutagen don't support it yet


I've been using Pygame with Python 3 for ages now. You can download Pygame for Python 3 here.

Maybe it works for you, but those releases don't appear to exist anywhere outside that page, and they're windows only. The latest versions on pypi are python2 only as far as I can tell.

User avatar
0x783czar
Posts: 13
Joined: Fri Sep 12, 2008 12:15 pm UTC

Re: Python 2.x vs. python 3.x

Postby 0x783czar » Sat Jan 25, 2014 12:11 am UTC

Python 3, all the way and unreservedly.

That being said, it won't fully happen until systems ship with python 3 by default. And systems won't ship with python 3 by default until they know the programs they rely on are compatible with python 3. It will happen (soon I hope) but it's going to take some time to fully transition.

However new students should be taught python 3 first, and all new projects should be written using it wherever possible. And if you're a project maintainer it's your responsibility to start working on python 3 compliance now. Let's have Python 2 die a noble death while maintaining it's dignity :)

Foxical
Posts: 0
Joined: Wed Feb 26, 2014 11:47 am UTC
Location: Somewhere

Re: Python 2.x vs. python 3.x

Postby Foxical » Wed Feb 26, 2014 8:23 pm UTC

I'm a noob, so I grew up on Python 3.x. For all its nuances and incompatibilities with old frameworks, I much prefer it over Python 2.x. In the long run, it'll be more futureproof, and Unicode strings are definitely one of its selling points.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 7 guests