sdm7g at Virginia.EDU
Fri Jan 25 12:36:55 EST 2002
On Fri, 25 Jan 2002, Vincent Foley wrote:
> I'm no expert on the Python language, or OO programming, but it's
> possible in the language Ruby <www.ruby-lang.org> to add new methods to
> existing classes. For example, it is possible to had a rot13 method to
> the String class. Is this one of the things this Python type and class
> unification renders possible?
You can create a new string type in Python that adds a rot13 to the
builtin string type, if that's what you mean. This is new in Python2.2.
In previous versions, you could not inherit directly from a builtin
type, but you could wrap the builtins in another python class and
inherit from and extend that class. ( See UserDict, UserList, for
If by [s/a/h/] "add a rot13 method to the String class" you mean
to modify the existing class by adding methods (what objective-C
calls 'categories' ) you can do that with Python classes, but I
don't believe you can do it with builtin types/classes.
-- Steve Majewski
More information about the Python-list