import problem

Dave Angel davea at davea.name
Mon Sep 16 10:08:18 EDT 2013


On 16/9/2013 00:05, Mohsen Pahlevanzadeh wrote:

> thank you, you gave me "how to get fish" instead of "fish", it's very
> better.

I'd suggest you make a diagram showing each file and indicate what files
it imports by an arrow.  If any arrows form a circle, you (may) have
recursive imports.

You should try to organize your code so you don't have any loops in the
above diagram.  In reasonable designs, you can do that by factoring out
some of the code into new bubbles.  But if you have too many bubbles
already, that just makes it harder to keep track of.

The recursion can sometimes be debugged more easily by eliminating the
"from xxx import *" forms., which really hides what things you get.
You'll only get those symbols already defined in the particular loop,
(which is generaly the ones defined before its import statment) and you
won't find out about the missing one till you try to use it later.

It can sometimes be mitigated by using from xxx import y1, y2  where you
explicitly define those things before the import statement.

However, both of these require you to have the imports somewhere NOT at
the top of the file.  And that can cause other problems.

Best is to avoid any loops in the diagram.

-- 
DaveA




More information about the Python-list mailing list