I inherited some old Django code where one of the modules is named global
(full name in INSTALLED_APPS
being 'labweb.global'
), which holds the models and views that drive the front page and some other scattered parts of the the site. However, global
is a Python keyword, so this smells...but it works.
I'm ~99% sure that it's a bad idea to name modules after keywords, but I'm somewhat amazed that it works at all. How does Django not seem to care?
Yes, of course it's a Bad Idea. Of course you can't import such a module directly:
import global # or any other keyword
just raises SyntaxError
at compile-time. But perhaps that's the point? That is, perhaps the designer wanted to make sure the module couldn't be imported directly (but only via trickery). I don't know - I'm just trying to be generous there ;-)
This is probably the easiest way to import such a module. Here's file global.py
:
print "I'm global!"
And then:
>>> import importlib
>>> importlib.import_module("global")
I'm global!
<module 'global' from 'global.py'>
There are other ways to do it. There's simply no way to import directly, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With