Ruby Impressions (fwd) (fwd)

Lulu of the Lotus-Eaters mertz at gnosis.cx
Sat Jan 12 02:42:56 EST 2002


adamspitz at bigfoot.com (Adam Spitz) wrote:
| class Person:
|     def __init__(self, name, age, gender):
|         self.name, self.age, self.gender = name, age, gender
|         self.doSomeStuff()
|I'd like to be able to tell Python, "Make me an __init__ method that
|takes these three parameters, stores them as attributes, and then does
|this other stuff."

Like this?

  >>> class Person:
  ...     def __init__(self, **args):
  ...         self.__dict__.update(args)
  ...
  >>> p = Person(name='Joe',age=37,gender='M/F')
  >>> p.name
  'Joe'





More information about the Python-list mailing list