On Mon, 15 Dec 2014 19:08:17 -0800 Mark Roberts <wiz...@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. _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com