Module imports during object instantiation

Ritesh Raj Sarraf riteshsarraf at gmail.com
Sat Aug 11 23:18:02 EDT 2007


On Aug 11, 3:17 am, James Stroud <jstr... at mbi.ucla.edu> wrote:
> You do realize your import statement will only be called for nt and dos
> systems don't you?
>

Yes. I would like to load a Windows Python Module (which is, say a
specific implementation for Windows only) in such a condition where I
find that the platform is Dos/NT.

Loading it globally doesn't make sense because when from the same
class an object is created on a non-windows platfom, it would be
waste. It would either ImportError or else just load the module and
never use it.

As per my understanding __init__ is executed only once during object
creation. For such situations (that I've explained above), I think
__init__() is the correct place to put imports.

Ritesh




More information about the Python-list mailing list