Any way of adding methods/accessors to built-in classes?
Tim Chase
python.list at tim.thechases.com
Wed Oct 25 16:22:33 EDT 2006
More information about the Python-list mailing list
Wed Oct 25 16:22:33 EDT 2006
- Previous message (by thread): Any way of adding methods/accessors to built-in classes?
- Next message (by thread): Any way of adding methods/accessors to built-in classes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> the builtins, but not being able to do things like
> '[1,2,3]'.length drives me a little nuts.
You mean like
'[1,2,3]'.__len__()
That gets you the length of the string, which is what one would
expect, calling the __len__() method on a string. The same works
for an array:
[1,2,3].__len__()
If you want to convert the string to the thing it's representing,
you can use the eval() function:
eval('[1,2,3]').__len__()
All very straightforward.
-tkc
- Previous message (by thread): Any way of adding methods/accessors to built-in classes?
- Next message (by thread): Any way of adding methods/accessors to built-in classes?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list