[Tutor] adding type methods?

Thomi Richards thomi at imail.net.nz
Thu Oct 23 00:31:47 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi guys,


I'm just wondering whether it's possible to add methods to a python built in 
type. for example:

>>> s = "this is a string"
>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', 
'__ge__', '__getattribute__', '__getitem__', '__getnewargs__', 
'__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', 
'__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', 
'__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 
'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 
'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 
'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> s.upper()
'THIS IS A STRING'


Is there an easy way to add more functions to these built in types, without 
having to compile python from source?

This is simply a random thought, without any practical application intended 
for it (so feel free to ignore)...

any ideas?

- -- 
Thomi Richards,
http://once.sourceforge.net/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/l1mz2tSuYV7JfuERAqXeAJ9acB/Ktbu52jW+B1CUFUfQpqyt+gCfcqfT
bQPzQ4hWtEs1fblgUftFsFU=
=wKc1
-----END PGP SIGNATURE-----




More information about the Tutor mailing list