Re: importing quixote.server
Mike Orr <[email protected]>
| Newsgroups | gmane.comp.web.quixote.user |
|---|---|
| Message-ID | <[email protected]> |
On 10/8/05, mario ruggier <[email protected]> wrote: > Why might this be? > > $ python > Python 2.4.2 (#1, Oct 3 2005, 16:22:31) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import quixote > >>> from quixote import server > >>> quixote.server > <module 'quixote.server' from > '/usr/local/lib/python2.4/site-packages/quixote/server/__init__.pyc'> > >>> ^D > $ python > Python 2.4.2 (#1, Oct 3 2005, 16:22:31) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import quixote > >>> quixote.server > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: 'module' object has no attribute 'server' > >>> quixote.__version__ > '2.2' > >>> Python's import statement really does two different things. from MODULE import SYMBOL from PACKAGE import MODULE So far so good. But if you have a package inside a package, as in quixote/server/simple_server.py), you cannot do: import PACKAGE PACKAGE.PACKAGE # No, the subpackage has not been imported. # PACKAGE contains only the variables defined in # PACKAGE/__init__.py . What you want to do is: import quixote import quixote.server # Or "from quixote import server". This loads only the variables in quixote/server/__init__.py . If you want to refer to a module in the quixote/server package, you have to import it separately. import quixote.server.simple_server or from quixote.server import simple_server or from quixote.server.simple_server import run -- Mike Orr <[email protected]> or <[email protected]>