"import foo" and "from foo import bar"
Justin Sheehy
dworkin at ccs.neu.edu
Mon Jun 12 21:15:57 EDT 2000
jajs at NOSPAMretemail.es (Juanjo Álvarez) writes:
> It's better to write the "from string import join" form or it's exactly
> the same (in memory use and performance) that "import string"?
There is a small performance benefit to the 'from' approach, but I
usually find that it is outweighed by the fact that it is much easier
to read and understand the code later if you don't do that.
The only time that I would recommend doing that sort of thing (other
than in modules that explicitly suggest that you do so) is if you are
going to reference that name _many_ times, such as inside a huge for-loop.
In that case, it may be worth it to get it into a local variable first.
-Justin
More information about the Python-list
mailing list