Python OOP newbie question: C-Struct-esque constructions
python_hacker at example.com
Mon Aug 12 17:33:18 CEST 2002
On Mon, 12 Aug 2002 04:03:31 -0400, Gerhard Häring wrote:
> In article <pan.2002.08.12.03.42.26.693124.11376 at example.com>, Jonathan
> S wrote:
>> that way I could access the items from x by name, like x.frog,
>> x.s_frog, etc.
>> I can do what I need to do, but this solution seems a bit, well,
> More importantly, it's wrong. To set instance attributes, you need to
> use self: self.frog = list, etc.
Originially I had it written as
self.frog = list
#...and so on...
(I guess this question would also be for Jay, who also was kind enough to
answer) but, er, whats the difference between a Class attribute and an
instance attribute? is this like the java 'static final' idiom?
>> Any suggestions as to how to do this more python-esque?
> I see nothing wrong with your solution. You could implement it with less
> code, but that's not necessarily more readable:
> def __init__(self, list):
> self.frog, self.s_frog, self.spam, self.spam_spam = lists[:3]
this is what I was looking for! thanks!
More information about the Python-list