Confused about namespaces

Bruno Desthuilliers bdesth.quelquechose at
Sat Nov 19 12:08:27 CET 2005

KvS a écrit :
> Ok, makes sense but didn't seem "natural" to me, 

It will seem more natural if you understand that modules should be 
modulars (ie: low coupling, high cohesion). A module should *never* 
bother about no rely upon other modules being imported by the module it 
imports itself. Err, not quite clear... Let's rephrase it : a module 
should only used symbols it defines itself or that it *explicitely* 
imports from other modules.

> although it is an
> obvious consequence of what you just pointed out, namely that modules
> are evaluated in their own namespace, something to keep in mind... On
> the other hand it does apparently work recursively "the other way
> around" since I didn't explicitly import wx in but only
> indirect via importing GUIclasses in which wx is imported right?

You've already got technical answers to this - please carefully (re)read 
Alex Martelli's post.

Now about coding style: this is *very* Bad Style(tm). Your main module 
imports should look like this:

import wx
# import settings -> we don't use the settings module here
from GUIclasses import KFrame


and the GUIclasses module's import :

import wx
import wx.lib.mixins.listctrl  as  listmix
import settings -> *here* we use the settings module


Python's philosophy is to favour readability.

Talking about imports, take time to open your Python interactive shell 
and type "import this" !-)

More information about the Python-list mailing list