[Tutor] Importing Modules Within Classes
Kent Johnson
kent37 at tds.net
Fri Oct 7 17:12:15 CEST 2005
Pierre Barbier de Reuille wrote:
> (never import
> a module in a small function likely to be called in an inner-loop !)
That's good advice, but I would say "in a *time-critical* inner-loop". After the first import, importing a module is fast, it is just a few dictionary lookups (looking up the module in sys.modules) and a dictionary write (to the local namespace). It's only the first import that is potentially expensive.
Kent
More information about the Tutor
mailing list