Python OOP newbie question: C-Struct-esque constructions

Jonathan S python_hacker at example.com
Mon Aug 12 03:36:51 EDT 2002


hello all,

I'm working on a news-downloading program for myself, and I want to take the
list returned from the xover() method of the nntplib module and put it into a
class so that each item in that list can be referenced by name. 

the way I figured to do it was something like this:

-------------------------------
class xover_data():
    frog = ""
    s_frog = ""
    spam = ""
    spam_spam = ""
    
    def __init__(self, list):
		frog = list[0]
		s_frog = list[1]
		spam = list[2]
		spam_spam = list[3]

alist = ['ribbit', 's_ribbit', 'spam', 'spamspam']
x = xover_data(alist)
-------------------------------

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,
unsophisticated. 

Any suggestions as to how to do this more python-esque? 

thanks,
Jonathan



More information about the Python-list mailing list