8

I was using python-future for a while until profiling revealed that my program's 50 million instantiations of newint was increasing the runtime of my program 10-fold. I have the thing running fine in Python 3, but trying to make it compatible with 2 and 3 is highly desired as I'm kind of alone in my organization as the sole Py3 pusher.

future has some nice documentation that says to throw

from __future__ import (absolute_import, division,
                        print_function, unicode_literals)
from future.builtins import *

up as a boilerplate in all my source files then code in standard 3. However, because it seems to be ever-so-slightly heavy, when parsing lots of text files it's a drag.

six seems to be much more lightweight, but what's the usual way to use it? The documentation is a bit flat and easy to gloss over... I currently have something like:

from __future__ import (
        absolute_import, division, print_function, unicode_literals)
import six
from six.moves import (zip, filter, map, range, reduce, input)

There's something about lazily loading modules on attribute-access however; can I just say from six.moves import *, or will it actually load all the HTTP, Tkinter, etc. jazz then and there? What are the "best practices" for developing Py2+3 code with six?

Charles
  • 50,943
  • 13
  • 104
  • 142
Nick T
  • 25,754
  • 12
  • 83
  • 121
  • 2
    You seem to have multiple questions in one, and most of them are overly broad for StackOverflow (like asking 'What are the "best practices'—to answer that, someone either has to write the equivalent of a blog post or tutorial, which is inappropriate for SO, or just find one and link to it, which is also inappropriate). Please edit this into a single question that can be answered on a SO-type site. – abarnert Feb 13 '14 at 20:28
  • I'll try to answer what looks like the most specific and answerable question in your question, in hopes that can get you started. – abarnert Feb 13 '14 at 20:29
  • @abarnert I'm looking for the equivalent to [`future`'s "Quick-start" documentation](http://python-future.org/quickstart.html#if-you-are-writing-code-from-scratch). It seems like it could be a fairly concise answer. – Nick T Feb 13 '14 at 20:31
  • If you're asking people to search for documentation for you and provide a link, that's not an appropriate question for SO. – abarnert Feb 13 '14 at 20:31
  • However, have you read [Writing Source-Compatible Python 2/3 Code](http://docs.python.org/dev/howto/pyporting.html) in the official Python docs, which explains a bit about using `six`, and a bunch of stuff that isn't specific to it? – abarnert Feb 13 '14 at 20:37
  • @abarnert I've tried and that documentation doesn't seem to exist. I pointed at that documentation for an example of how terse I could imagine an answer being: "Just do X, Y, Z and you're golden 99% of the time." I'm still not sure about the "multiple questions"; I use more than one question mark, but it's basically the same question couched in a few different ways. – Nick T Feb 13 '14 at 20:38
  • When you say "that documentation doesn't seem to exist", what are you talking about? The docs I linked to certainly don't exist. A quick-start for `six` may not exist, but in that case, surely you're asking for something impossible. – abarnert Feb 13 '14 at 21:10
  • As for the multiple questions: When you ask "can I just say from six.moves import *, or will it actually load all the HTTP, Tkinter, etc. jazz then and there?", do you really expect the answer to that question to be the same as the answer to "where is the quick-start documentation for `six`"? – abarnert Feb 13 '14 at 21:10
  • @abarnert do I have any semblance of a good question? I'd welcome a cursory edit if there is some benefit to be had in keeping this. – Nick T Feb 13 '14 at 21:26
  • This is a potentially good question. Please be more specific: post some sample code and your stats. – Apalala Feb 14 '14 at 17:11

0 Answers0