caught in the import web again

Dave Angel davea at davea.name
Mon Nov 17 17:17:07 EST 2014


"Charles T. Smith" <cts.private.yahoo at gmail.com> Wrote in message:

> Well, I guess that's the definitive answer... the tips for delaying
> import are good, I'll try to leverage them.
> 
> I was hoping there would be a way to have python postpone evaluation
> similar to C's forward references.
> 

In a module that might get tangled in a cycle, avoid global code
 that depends on other modules.  Instead of putting such
 initialization at top level, put inside a function that gets
 called after all suspect imports are completed. (That function
 has global keywords ). 

Similarly avoid class attribute initialization at class level, if
 such initialization references higher level modules.

-- 
DaveA




More information about the Python-list mailing list