Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54228

Re: import problem

From Dave Angel <davea@davea.name>
Subject Re: import problem
Date 2013-09-16 14:08 +0000
References <mailman.8.1379298217.18130.python-list@python.org> <5236735f$0$29988$c3e8da3$5496439d@news.astraweb.com> <1379304304.24093.1.camel@debian>
Newsgroups comp.lang.python
Message-ID <mailman.30.1379340521.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

import problem Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-16 06:53 +0430
  Re: import problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-16 02:56 +0000
    Re: import problem Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-16 08:35 +0430
    Re: import problem Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-16 11:14 +0430
    Re: import problem Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> - 2013-09-16 11:26 +0430
    Re: import problem Dave Angel <davea@davea.name> - 2013-09-16 14:08 +0000

csiph-web