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


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

Re: Import order question

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-02-18 00:11 +1100
Last post2014-02-18 00:11 +1100
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: Import order question Ben Finney <ben+python@benfinney.id.au> - 2014-02-18 00:11 +1100

#66603 — Re: Import order question

FromBen Finney <ben+python@benfinney.id.au>
Date2014-02-18 00:11 +1100
SubjectRe: Import order question
Message-ID<mailman.7094.1392642709.18130.python-list@python.org>
Nagy László Zsolt <gandalf@shopzeus.com> writes:

> I have a class hierarchy like this:
>
> Widget <- VisualWidget <- BsWidget
>
> and then BsWidget has many descendants: Desktop, Row, Column, Navbar
> etc.

None of this implies anything about which modules you place these in;
Python is not Java, and you should be putting your class definitions
wherever makes the most sense for reading and access.

> Here is the problem: these methods should create instances of Row,
> Column and Navbar. But this leads to circular imports.

It should not; Python is not Java.

Use modules to group your class definitions conceptually. There is no
need whatever to separate every class into a different module.

>  * I want to put different widget classes into their corresponding
>    different source files

Please, don't.

> This might be a bad idea, but then please tell me why it is bad, and
> what would be the right code pattern for this task.

Not only does it lead to the problem you've described, it makes the code
needlessly difficult to read.

Pyth is not Java
<URL:http://dirtsimple.org/2004/12/python-is-not-java.html>.

-- 
 \           “I do not believe in forgiveness as it is preached by the |
  `\        church. We do not need the forgiveness of God, but of each |
_o__)                    other and of ourselves.” —Robert G. Ingersoll |
Ben Finney

[toc] | [standalone]


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


csiph-web