Albert-Jan Roskam wrote:

> I want to import a module upon instantiation (not definition) of a class.
> What is the best way to do this? In my case, I need the "icu" module in
> only one place/class of the program. If that class won't be used, I don't
> want to have an ImportError. Also, it might be nice to do the imports only
> when you actually need that functionality. It's probably not really
> PEP-compliant to put the imports somewhere else than at the top of the
> module, but I can live with that.
> 
> 
> import some_nonbuiltin  # I don't want it here!
> 
> 
> class KlassA(object):
>     import some_nonbuiltin  # nope
> 
>     def __init__(self):
          global some_nonbuiltin
          import some_nonbuiltin

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to