__name__ becoming read-write?

Anthony Baxter anthonybaxter at gmail.com
Mon Aug 23 17:40:29 CEST 2004


On Mon, 23 Aug 2004 14:07:42 GMT, Arthur <ajsiegel at optonline.com> wrote:
> 
> 
> Did I hallucinate something about __name__ becoming read-write?

> Better get my facts straight first....
> 
> But if true that would seem to solve the main objection to:

> the_horrible_name_I _need_to_call=transform(__f)

> And would mean that a byproduct of the PEP318 implementation would go
> 50% toward obviating the need for a PEP318 implementation.  At least
> by one measure.

No, it is now read-write, thanks to mwh. I think, though, that you're
misunderstanding the difference between setting a local variable in
the function, called '__name__', and setting the actual __name__ of
the function object.

>>> def foo(): pass
... 
>>> foo.__name__ = 'bar'
>>> foo.__name__
'bar'
>>> def foo():
...   __name__ = 'bar'
... 
>>> foo.__name__
'foo'
>>> foo.func_code.co_names  
('__name__',)



More information about the Python-list mailing list