In <[EMAIL PROTECTED]>, Francesco
Guerrieri wrote:

> Now the question is this:
> I would like to initialize such an object in this way:
> a = myList()
> a = [[1, 2, 3], [4, 5, 6, 7]]
> a.pad()
> # and now a _should_ contain [[1, 2, 3, ""], [4, 5, 6, 7]]
> 
> 
> Obviously this doesn't work, because when at the second line I do the
> initialization, type(a) becomes <type 'list'>, and so I get the
> expected AttributeError since pad cannot be found.

You don't initialize in the second line, you just rebind `a` to a
completely different object.  Names don't have types in Python, objects do.

`list()` takes an optional argument.  Just make sure your derived type
does to and passes this to the base class `__init__()`.  Then you can
create an instance like this:

a = MyList([[1, 2, 3], [4, 5, 6, 7]])

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to