[Tutor] class arguments?

Alan Gauld alan.gauld at btinternet.com
Fri Jan 23 00:29:59 CET 2009

"Alan Gauld" <alan.gauld at btinternet.com> wrote 

>> is there a way to give arguments to a class definition? 

I see that Kent interpreted your question differently to me. 
If you do mean that you want to dynamically define class 
attributes rather than instance attributes then __init__() 
won't work. But I'd be interested to understand why and 
how you would want to do that? And in particular how 
you would use them after creating them?

> Yes thats what the __init__ method is for.
> class MonoList:
>   def __init__(self, lst, typ, num):
>       self.item_type = typ
>       self.number = num
>      etc...
> myList = MonoList([1,2,3], int, 3)    # or whatever...

Alan G.

More information about the Tutor mailing list