Diez B. Roggisch wrote:
> J schrieb:
>> On Mon, Dec 7, 2009 at 16:57, Diez B. Roggisch <de...@nospam.web.de>
>> wrote:
>>
>>>> if I put the import at the beginning of the class, it just dawned on
>>>> me that perhaps I still have to explicitly call the function by class:
>>>>
<snip>
> I'm not annoyed. I just wonder from what you got the impression that
> import statements are something that belongs inside functions - even if
> python allows it.
> 
> I don't know of any other language (I don't do ruby & perl) that allows
> this, C/C++, java, Pascal, Haskell, ML - all of them declare their
> intended use of a library on the beginning of a file.
> 
> You seem to really be really determined to place them everywhere else...
> 
> 
> 
> 
> Diez


I have found one good use for using import within functions.

I maintain a module of useful miscellaneous python functions I have
written over the years, it's quite the hodgepodge though and it's not
something I would really want to package and distribute in its entirety,
especially as there are many uses of modules outside the standard lib.

I use it 'as is' during initial development with each function importing
what it needs at the top of the function definition. This doesn't seem
to affect performance and even if it did it would only be on my dev box.

When it's time to bundle an app for distribution I copy the few
functions that are actually used to a new module and refactor it so the
imports are all at the top. Having the imports within the functions
makes it very easy to keep track of these dependencies so I don't have
to sift through a list of 50 different imports, weeding out the ones I
don't need whenever I do this.

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to