Overriding a global
Dave Angel
d at davea.name
Mon Dec 12 16:43:54 EST 2011
On 12/12/2011 04:28 PM, Steven D'Aprano wrote:
> On Mon, 12 Dec 2011 12:13:33 +0100, Jean-Michel Pichavant wrote:
>
>> Using the same name for 2 different objects is a bad idea in general.
> We have namespaces precisely so you don't need to care about making names
> globally unique.
>
>
True, but in this code, the function is trying to both use the global
value, but also a local that deliberately has the same name, but a
different meaning and "value". The CPython compiler doesn't make this
easy, and I think the globals() technique is unnecessarily obscure, as
is the default-argument trick.
If a function knows of the presence of a global, it's not asking too
much for it to not re-use the same name in local scope.
Since it seems to be in vogue to propose language changes, how about a
new place for 'as' ?
def myfunc():
global logger as g_logger
logger = g_logger.debug('stuff').getChild('function')
--
DaveA
More information about the Python-list
mailing list