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. Advertisements

  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. Advertisements

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. Robert Oschler
    Replies:
    3
    Views:
    597
    Christopher T King
    Jul 27, 2004
  2. Gerard Flanagan
    Replies:
    3
    Views:
    665
    Terry Hancock
    Nov 19, 2005
  3. John O'Hagan

    Instance attributes vs method arguments

    John O'Hagan, Nov 25, 2008, in forum: Python
    Replies:
    8
    Views:
    383
    John O'Hagan
    Nov 26, 2008
  4. M.-A. Lemburg
    Replies:
    4
    Views:
    607
  5. Raj Singh
    Replies:
    2
    Views:
    335
    Rick DeNatale
    May 29, 2008
  6. Greg Hauptmann
    Replies:
    9
    Views:
    474
    Loren Segal
    Jun 16, 2008
  7. Olive
    Replies:
    4
    Views:
    428
    Olive
    Jul 6, 2012
  8. Jayden
    Replies:
    16
    Views:
    805
    Steven D'Aprano
    Sep 29, 2012
Loading...