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.  Try
the following instead:

    def __init__(self, **kwargs):
        self.values = kwargs

Then access the values with:

    x = self.values['name']

or, safer:

    x = self.values.get('name', '<no_name>')

If you are determined to create names in a namespace, on the fly,
look at the "exec" command (http://docs.python.org/ref/exec.html).
But, that's a dangerous way to code.

Dave



-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to