Why can function definitions only use identifiers, and not attribute references or any other primaries?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Apr 24 20:52:49 CEST 2009


Marco Mariani wrote:
> Scott David Daniels wrote:
> 
>> I am afraid it will make it too easy to define functions in other
>> modules remotely, a tempting sharp stick to poke your eye out with.
>> Imagine debugging a pile of code that includes a module with:
>>     import random
>>     def random.random():
>>         return .42
> 
> No need to imagine. I can do the same, one line shorter:
> 
>  >>> import random
>  >>> random.random = lambda: .42

I'm pointing out that that one is called lambda, so function.__name__
works out nicely.  Similarly (and to my min more treacherously), the
     def a.b(...):
         ...
doesn't give you a good clue about where to look for the definition.
That's all, not "monkeypatching is evil", but "monkeypatching should
stand out visually."

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list