Namespace hack

Temia Eszteri lamialily at cleverpun.com
Thu May 24 23:02:05 EDT 2012


[Default] On 25 May 2012 02:47:11 GMT, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:

>Do you object to the ability to write standard Python modules?
>
># module.py
>def spam(obj, n):
>    return len(obj) + n
>
>def ham(obj):
>    return spam(obj, 23)
>
>
>By your apparent misunderstanding of the Zen, you think that this should 
>be written with oodles of more explicitness, 'cos explicit is always 
>better, right?
>
>keyword.def globals.spam(locals.obj, locals.n):
>    keyword.return builtin.len(locals.obj) + locals.n
>
>keyword.def globals.ham(locals.obj):
>    keyword.return globals.spam(locals.obj, 23)
>
>
>Python, like most (all?) non-trivial languages, has scoping rules so that 
>you can refer to names without explicitly specifying which namespace they 
>are in. So long as this is unambiguous, Explicit vs Implicit is 
>irrelevant if not outright wrong.
>
>My namespace decorator simply applies a slightly different set of scoping 
>rules to the ones you are already used to in modules. It's no worse than 
>nested functions (hardly a surprise, because it is built on nested 
>functions!) or module-level scoping rules.
>
>
>-- 
>Steven

But then we've got "Simple is better than complex", and "Complex is
better than complicated". Of course if we decided to start iterating
through the zen of Python's verses and continually modifying the
example code to fit, it would get rather silly rather fast.

~Temia
--
When on earth, do as the earthlings do.



More information about the Python-list mailing list