[Tutor] Namespace question

Dave Angel d at davea.name
Fri Jan 20 19:51:47 CET 2012

On 01/20/2012 01:34 PM, Tino Dai wrote:
> Hi everybody,
>       Got a namespace question framed inside a Django project (but I still
> think it's pertinent to Python). We moved and broke settings.py four
> different files in a separate directory called settings. So instead of
> doing a
>>>> import settings
>>>> settings.whatever
> We are having to do:
>>>> import settings
>>>> settings.settings.whatever
I would try to never have the same name used at two different scope 
levels.  if you have a module called settings, don't put it in a package 
called settings.  (Similarly, the familiar capitalization convention - 
name the file with lowercase, and a class within the file capitalized.)
> This is inconvenient and probably will break stuff especially with django
> framework code. Is there a way to play with the namespacing to have python
> have the former behavior rather than the latter behavior?
> Thanks,
> Tino
I haven't done it myself, but you can have package initialization code 
in  settings/__init__.py   that code can customize what the user sees 
when importing your package.

It's not clear to me what you're willing to change and what you cannot.



More information about the Tutor mailing list