Setting an class attribute with a given name in python while defining the class

Posted by kaleidomedallion on Stack Overflow See other posts from Stack Overflow or by kaleidomedallion
Published on 2010-03-25T22:14:33Z Indexed on 2010/03/25 22:23 UTC
Read the original article Hit count: 353

Filed under:
|
|

I am trying to do something like this:

property = 'name'
value = Thing()
class A:
  setattr(A, property, value)
  other_thing = 'normal attribute'

  def __init__(self, etc)
    #etc..........

But I can't seem to find the reference to the class to get the setattr to work the same as just assigning a variable in the class definition. How can I do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about class