create instance attributes for every method argument

Discussion in 'Python' started by Berco Beute, Jul 19, 2008.

  1. Berco Beute

    Berco Beute Guest

    I remember reading somewhere how to create an instance attribute for
    every method argument, but although Google is my friend, I can't seem
    to find it. This could likely be done way more elegant:

    =========================
    class Test(object):

    def __init__(self, a, b, c, d, e, f):
    self.a = a
    self.b = b
    self.c = c
    self.d = d
    =========================

    2B
    Berco Beute, Jul 19, 2008
    #1
    1. Advertising

  2. Berco Beute

    Peter Otten Guest

    Berco Beute wrote:

    > I remember reading somewhere how to create an instance attribute for
    > every method argument, but although Google is my friend, I can't seem
    > to find it. This could likely be done way more elegant:
    >
    > =========================
    > class Test(object):
    >
    > def __init__(self, a, b, c, d, e, f):
    > self.a = a
    > self.b = b
    > self.c = c
    > self.d = d
    > =========================


    http://code.activestate.com/recipes/280381/

    Personally, I prefer to spell it out like you did above.

    Peter
    Peter Otten, Jul 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gerard Flanagan
    Replies:
    3
    Views:
    427
    Terry Hancock
    Nov 19, 2005
  2. =?Utf-8?B?SXJ3YW5zeWFo?=
    Replies:
    4
    Views:
    2,434
    =?Utf-8?B?SXJ3YW5zeWFo?=
    Oct 30, 2007
  3. Raj Singh
    Replies:
    2
    Views:
    185
    Rick DeNatale
    May 29, 2008
  4. Greg Hauptmann
    Replies:
    9
    Views:
    231
    Loren Segal
    Jun 16, 2008
  5. Olive
    Replies:
    4
    Views:
    233
    Olive
    Jul 6, 2012
Loading...

Share This Page