Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20942
| Date | 2012-02-27 15:59 +0100 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: Question about circular imports |
| References | <jid2a9$n21$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.201.1330354794.3037.python-list@python.org> (permalink) |
Frank Millman wrote: > Hi all > > I seem to have a recurring battle with circular imports, and I am trying to > nail it once and for all. > > Let me say at the outset that I don't think I can get rid of circular > imports altogether. It is not uncommon for me to find that a method in > Module A needs to access something in Module B, and a method in Module B > needs to access something in Module A. I know that the standard advice is to > reorganise the code to avoid this, and I try to do this where possible, but > for now I would like to address the question of how to handle the situation > if this is otherwise unavoidable. > Hi Frank, If you consider it unavoidable you've already lost. There is no reliable solution to circular import except refactoring the code to place all common code elsewhere: wavbase.py wavread.py (import wavbase) wavwrite.py (import wavbase) Any code required by both waread and wavwrite would end up in wavbase. Is there anything that prevent you from doing this ? JM
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Question about circular imports Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-02-27 15:59 +0100
csiph-web