Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

Circular imports


On Mon, 28 May 2007 23:46:00 -0400, Ron Provost wrote

> [...] python is not happy about my circular imports [...]

A circular import is not a problem in itself. I'm guessing you're running into
a situation like this:

Module A imports module B and then defines an important class. Module B
imports A (which does nothing because A is already partially imported) and
then defines a class that depends on the class that is defined in module A.
That causes a NameError.

The root of the problem is that all statements are executed in the order in
which they appear, and B is imported before A had a chance to define the class
that B depends on.

Note that import statements don't have to be at the top of the file. Try
moving each import statement to the latest possible point in the code, i.e.
right before the first occurence of whatever names you're importing from the
respective modules. That way, each module gets to define as much as it
possibly can before it gets side-tracked by importing other modules.

If my guess doesn't help, you're going to have to post at least the
exception/traceback you're getting, and you're probably going to have to post
some code, too.

Good luck,

--
Carsten Haese
http://informixdb.sourceforge.net

On Tuesday 29 May 2007 00:08, Carsten Haese wrote:

I agree, waite until python complains.

You might try to remove all of the import
statements then add then as they are requested by
the program by a traceback error.

jim-on-linux

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc