On 6 March 2014 13:36, Ben Finney <[email protected]> wrote:

> Care to show a simple-as-possible example of this? Show a package
> ‘__init__’ module that does nothing but import another module from the
> package, and show that other module's minimal content.
>

Very odd, tried to do a simple test case of it, and it worked.

For my application I am developing however, if I add the following line to
the empty karaage/applications/__init__.py:

    import karaage.applications.hooks

I get the following stack trace when django tries to import
karaage.applications:

[...]
  File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line
40, in import_module
    __import__(name)
  File
"/home/brian/tree/django/karaage/karaage/karaage/applications/__init__.py",
line 1, in <module>
    import karaage.applications.hooks
  File
"/home/brian/tree/django/karaage/karaage/karaage/applications/hooks.py",
line 1, in <module>
    import karaage.applications.models as models
AttributeError: 'module' object has no attribute 'applications'

(for the purpose of this test, I deleted all other lines
in karaage/applications/hooks.py; i.e. both files only one line long)

Where obviously karaage.applications is defined. I can only guess that
there is implicit requirement to "import karaage.applications" in that last
statement, which would create a circular import loop.

If I change the __init__.py line to "from karage.applications.hooks import
*" it still crashes.

If however I change the line in hooks.py to the following, it no longer
crashes:

    from karaage.applications.models import Application

So, it seems that the implicit requirement to import "karaage.applications"
isn't there.

However, can't reproduce this on a simple test case, maybe something
specific to Django????? Doesn't make sense to me.

(this was relevant as I was trying to attach a function to a Django signal,
which in current versions of Django is best done in the application
__init__.py file)
-- 
Brian May <[email protected]>
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to