[Tutor] proper import syntax
Rob
uselesspython@yahoo.com
Sat, 08 Sep 2001 13:34:58 -0500
"David L. Lerner" wrote:
>
> Let's say I need to use several different functions from the module
> 'string'...
>
> Do I use 'from string import *', import each function individually, or put
> 'string.' in front of each function?
>
> I've seen it all three ways.
>
> Thank you
>
This is a great question, and I look forward to seeing the different
answers offered. Are you specifically interested in the answer as it
would apply to the string module, or as a practice in general?
Any time you face this decision for a given module, there are a number
of factors to consider. Most of the really interesting problems I've
seen people run into seem related to naming conflicts. "import string"
imports the module and directly executes the top-level part of the
module (but only the first time you import the module), whereas "from
string import *" imports each individual module element.
"from [some module] import *" is sometimes useful, but you need to
exercise some care to make sure you don't use names in your module that
are identical to names you import directly this way.
Rob
--
Aw, c'mon.... You indent ANYWAY!
Useless Python!
http://www.lowerstandard.com/python