Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66604
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'importing': 0.05; 'insert': 0.05; 'column': 0.07; 'problem:': 0.07; 'tries': 0.07; 'append': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'subject:question': 0.10; 'def': 0.12; 'stored': 0.12; 'be:': 0.16; 'etc.):': 0.16; 'hierarchy': 0.16; 'navbar': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'fix': 0.17; 'wrote:': 0.18; '(where': 0.19; 'widget': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'circular': 0.24; 'this:': 0.26; 'skip:_ 20': 0.27; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'code': 0.31; 'class': 0.32; 'advice': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'instances': 0.36; 'leads': 0.36; 'should': 0.36; 'follows:': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name': 0.63; 'here': 0.66; 'qualified': 0.72; 'nagy': 0.84; 'children.': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Import order question |
| Date | Mon, 17 Feb 2014 14:29:07 +0100 |
| Organization | None |
| References | <53020843.5010804@shopzeus.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p57bd81bc.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7095.1392643747.18130.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392643747 news.xs4all.nl 2865 [2001:888:2000:d::a6]:48033 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66604 |
Show key headers only | View raw
Nagy László Zsolt wrote:
> I have a class hierarchy like this:
>
> Widget <- VisualWidget <- BsWidget
>
> and then BsWidget has many descendants: Desktop, Row, Column, Navbar etc.
>
> Widgets can have children. They are stored in a tree. In order to manage
> the order of widgets, I need methods to append children. (And later:
> insert or prepend because they also have an order). So I would like to
> have methods like this:
>
> BsWidget.AppendNavbar(....)
> BsWidget.AppendRow(...)
>
> Here is the problem: these methods should create instances of Row,
> Column and Navbar. But this leads to circular imports.
>
> Here is code for BsWidget:
>
> from shopzeus.yaaf.ui.visualwidget import VisualWidget
>
> from shopzeus.yaaf.ui.bootstrap.row import Row
> from shopzeus.yaaf.ui.bootstrap.column import Column
> from shopzeus.yaaf.ui.bootstrap.navbar import Navbar
>
> class BsWidget(VisualWidget):
> """Visual widget for bootstrap.
>
> Adds extra methods for adding/removing content like rows
> columnsetc.""" def __init__(self,parent):
> <more code here>
>
> def AppendRow(self):
> return Row(self)
>
> def AppendColumn(self):
> return Row(self)
>
> def PrependRow(self):
> return Row(self,position=-1)
>
> <more code here>
>
>
> Here is code for ClassX (where ClassX can be: Row, Column, Desktop,
> Navbar etc.):
>
> from shopzeus.yaaf.ui.bootstrap.bswidget import BsWidget
> <more imports here>
>
> class ClassX(BsWidget):
> <more code here>
>
> The circular import is as follows:
>
> * I want to create a Desktop instance
> * I try to import shopzeus.yaaf.ui.bootstrap.desktop
> * That tries to import BsWidget
> * That tries to import Row
> * That tries to import BsWidget, which is importing -> I get an
> "ImportError: cannot import name BsWidger"
Hm, is that cut-and-paste? If so fix the name. If that doesn't work use
qualified names:
from shopzeus.yaaf.ui.bootstrap import row
[...]
def AppendRow(self):
return row.Row(self)
If that still doesn't work follow Ben's advice and be enlightened...
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Import order question Peter Otten <__peter__@web.de> - 2014-02-17 14:29 +0100
csiph-web