[Tutor] Class instantiation parameters

Jan Eden lists at janeden.org
Sun Aug 7 16:33:42 CEST 2005


Jan Eden wrote on 07.08.2005:

>But the assignment in the for loop obviously does not work with
>instance attributes. I will have to read up some more about instance
>attributes.

Ok... so this works:

class NewClass:
    def __init__(self, **parameters):
        self.data = {}
        for i in parameters.keys(): self.data[i] = parameters[i]

self = NewClass(arg1='Value', arg2='Another value', arg3='Yet another value')
print self.data

It seems that I need to add a dictionary as a data attribute to my instance object to do what I wanted to.

This is unfortunate, because it complicates my syntax: Instead of self.type, I need to use self.data['type'].

- Jan
-- 
I'd never join any club that would have the likes of me as a member. - Groucho Marx


More information about the Tutor mailing list