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


Groups > comp.lang.python > #66603

Re: Import order question

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Import order question
Date 2014-02-18 00:11 +1100
References <53020843.5010804@shopzeus.com>
Newsgroups comp.lang.python
Message-ID <mailman.7094.1392642709.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Re: Import order question Ben Finney <ben+python@benfinney.id.au> - 2014-02-18 00:11 +1100

csiph-web