[Tutor] Menu data from file
alan.gauld at btinternet.com
Mon Apr 5 00:54:40 CEST 2010
>I can not loop over each list item like:
> for eachMenuData in self.menuData():
>because when I read external txt file:
>I get the list of file lines instead of list of external list (tuple)
Thats right you will need to parse the data to convert it into the format
This is one reason you might find it easier to use XML for storing the data
and use a tool like ElementCTree to parse it.
Alternatively you could make your data file a Python module and import it
for eachMenuData in menudata.menuData:
Or another option is to store the data as a tuple in a pickle or shelve
But they you need to create it from Python initially.
My personal favourite for this kind of application is the module approach.
Just edit the menu module when you want to modify the menu structure
and the import will see it as Python data.
Author of the Learn to Program web site
More information about the Tutor