Extend a class?

Mike 'Cat' Perkonigg blablu at gmx.net
Mon Sep 25 16:58:27 CEST 2000

npirzkal at eso.org (Nor Pirzkal) wrote in <39CF5A9F.8C46BC7A at eso.org>:

>     I have a stupid question:
>     I would like to know if I could easily create a module, say called
>futils.py, which would allow me, once loaded, to add some methods to
>various objects, such as lists. I would like to be able to do something
>where writeasciifile() is a function that would take care of doing
>various (obscure) things....

AFAIK is a list a builtin data type, not a class.

Just create a class:

class mylist:
    	def __init__ (self, aList):
    	    	self.aList = aList
    	def writeasciifile (self, fileName):
    	    	... (some obscure things)

You have to initialize your instance with:

l = mylist (["123",1,2,4])

instead of:

l = ["123",1,2,4]

but then you can do:



More information about the Python-list mailing list