Two minor syntactic proposals
Barry A. Warsaw
barry at digicool.com
Mon Jun 18 02:07:54 EDT 2001
GM> Suppose you have a class and want to add a new method to
GM> it. (Why? It's someone else's, you aren't allowed to change
GM> the source, and subclassing won't do because these things are
GM> created by code you don't control.)
GM> You can do it, thus:
| def new_method(self, x):
| something_else()
| return x+1
| Thing.new_method = new_method
Long ago, I propsed being able to do something like
class Thing:
pass
def Thing.new_method(self, x):
something_else()
return x+1
No new syntax is necessary, and it would allow more separation of
interface and implementation, allowing the /interface/ to be the class
definition, maybe even scarecrow-ish in nature, while the
implementation could be completely separated into a separate file, or
farther down in the same file.
It never caught on, but this was in the (way) pre-PEP days. If
there's interest, I could write up a PEP on this.
-Barry
More information about the Python-list
mailing list