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

Marco Mariani marco at sferacarta.com
Fri Apr 24 04:23:01 EDT 2009


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.

It's not very hard at the moment, and I don't see lots of eyes flying 
by. I don't know about Ruby where monkeypatching seems to be common 
practice, though.

> 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




More information about the Python-list mailing list