[Python-Dev] Python 2.x and 3.x use survey, 2014 edition (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Tue Dec 16 11:45:27 CET 2014
- Previous message: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
- Next message: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 15 Dec 2014 19:08:17 -0800 Mark Roberts <wizzat at gmail.com> wrote:
So, I'm the guy that used the "hate" word in relation to writing 2/3 compliant code. And really, as a library maintainer/writer I do hate writing 2/3 compatible code. Having 4 future imports in every file and being forced to use a compatibility shim to do something as simple as iterating across a dictionary is somewhere between sad and infuriating - and that's just the beginning of the madness.
Iterating accross a dictionary doesn't need compatibility shims. It's dead simple in all Python versions:
$ python2 Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
d = {'a': 1} for k in d: print(k) ... a
$ python3 Python 3.4.2 (default, Oct 8 2014, 13:08:17) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information.
d = {'a': 1} for k in d: print(k) ... a
Besides, using iteritems() and friends is generally a premature optimization, unless you know you'll have very large containers. Creating a list is cheap.
From there we get into identifier related problems with their own compatibility shims - like str(), unicode(), bytes(), int(), and long(). Writing 2/3 compatible Python feels more like torture than fun.
It depends what kind of purpose your code is written for, or how you write it. Unless you have a lot of network-facing code, writing 2/3 compatible code should actually be quite pedestrian.
Regards
Antoine.
- Previous message: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
- Next message: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]