[Tutor] using **kwargs in __init__() as attributes

Tim Golden mail at timgolden.me.uk
Mon Oct 1 17:34:15 CEST 2007


Dave Kuhlman wrote:
> On Mon, Oct 01, 2007 at 04:51:53PM +0200, J?nos Juh?sz wrote:
>> Dear Tutors,
>>
>> I would like to make a new class instance, where
>> the intance attributes coming from the kwargs hash.
>>
>> class ADUser:
>>     def __init__(self, **kwargs):
>>         for key in kwargs.keys():
>>             self.key = kwargs[k]
>>
> 
> You are asking a more sophisticated form of a question that has
> been asked on this list several times before: 
> 
>     "How do I create names in a namespace from string values?"
> 
> It's likely that you do not really want (or need) to do this.

Also, on the off-chance (from the name of the class) that you're
implementing a wrapper around Active Directory, have a look at:

   http://tgolden.sc.sabren.com/python/active_directory.html

to see if it meets your needs already or is at least a
starting point.

TJG


More information about the Tutor mailing list