"import foo" and "from foo import bar"

Juanjo Álvarez jajs at NOSPAMretemail.es
Tue Jun 13 20:09:29 EDT 2000


Justin Sheehy dijo sobre Re: "import foo" and "from foo import bar",
en fecha: 12 Jun 2000 21:15:57 -0400

|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.

True.

|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.

I have followed your advice to make aliases to module symbols in a huge loop 
and now my program runs 15% faster!

|In that case, it may be worth it to get it into a local variable first.

Thanks Justin and Thomas. This newsgroup amazes me increasingly, I post
the message and in 20 minutes, Wham! two good answers.




More information about the Python-list mailing list