Different kinds of Import Errors
kyosohma at gmail.com
kyosohma at gmail.com
Tue Nov 27 09:13:23 EST 2007
On Nov 27, 7:35 am, Thomas Guettler <h... at tbz-pariv.de> wrote:
> If you look at this code, you see there are two kind of ImportErrors:
>
> 1. app_name has no attribute or file managment.py: That's OK.
> 2. managment.py exists, but raises an ImportError: That's not OK: reraise
>
> # Import the 'management' module within each installed app, to register
> # dispatcher events.
> for app_name in settings.INSTALLED_APPS:
> try:
> __import__(app_name + '.management', {}, {}, [''])
> except ImportError, exc:
> if exc.args[0]!='No module named management':
> raise
>
> I am searching a better solution, since in a future version of python
> the string 'No module namend management' might be changed.
>
> Any better solution?
I would assume that in the future versions of Python, it would still
mention the word "management". In that case, you could do something
like this in the except clause:
# untested
args = exc.args[0]
if args.find('management') != -1:
raise
Mike
More information about the Python-list
mailing list