Question

Got a slight problem with some appengine code that I can't work out (may just be because it's late)

I have a folder called modules that has the following items:

-modules
 : __init__.py (blank)
 : checklogin.py
 : customhandlers.py
 : datastoretools.py
 : emailtools.py

In my code I use all of these, therefore I'm doing this to import them:

from modules import *

Everything works bar emailtools. This:

emailtools.sendNotificationEmail('assignee',report,True)

Results in this error:

File "/home/tom/dev/ad-project/handlers/reporterhandler.py", line 42, in get
emailtools.sendNotificationEmail('assignee',report,True)
NameError: global name 'emailtools' is not defined

This happens wherever I try to use it, but the other three work perfectly fine, any ideas why? Or should I just import them all rather than using *?

Was it helpful?

Solution

This shouldn't work at all. It seems that this wildcard is not the only one You have used. Maybe other modules came from other wildcards.

In any cases wildcard is undesirable according to PEP 8:

Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance).

P.S. I assume You use windows otherwise Modules can't be imported as modules I think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top