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


Groups > comp.lang.python > #20942 > unrolled thread

Re: Question about circular imports

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2012-02-27 15:59 +0100
Last post2012-02-27 15:59 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Question about circular imports Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-02-27 15:59 +0100

#20942 — Re: Question about circular imports

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2012-02-27 15:59 +0100
SubjectRe: Question about circular imports
Message-ID<mailman.201.1330354794.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web