Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > create instance attributes for every method argument

Reply
Thread Tools

create instance attributes for every method argument

 
 
Berco Beute
Guest
Posts: n/a
 
      07-19-2008
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
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      07-19-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an instance when the argument is already an instance. Olive Python 4 07-06-2012 02:01 PM
why can't an instance instantiated within a class method access aprotected instance method? Greg Hauptmann Ruby 9 06-16-2008 10:16 AM
instance method adding another instance method to the class Raj Singh Ruby 2 05-29-2008 10:09 PM
Can you set a class instance's attributes to zero by setting the instance to zero? Gerard Flanagan Python 3 11-19-2005 06:58 PM
TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead) arotem Python 4 10-17-2005 07:52 AM



Advertisments