How to read ansic file into a pre-defined class?

Ying Zu zuying at gmail.com
Fri Jan 7 22:24:01 EST 2011


How to read ansic file into a pre-defined class?

I have a series of files written in the following format,

2         # number of classes
100       # number of items for the first class object 
0   foo
1   foo
...
99  foo
150       # number of items for the second class object 
0   bar
1   bar
...
149 bar

ultimately I want to read the file to two *structs* (sorry for my C
jargon, just started playing with Python), with attributes
number_of_items and data_array.

I wrote a simply code to read and split each line into a list, then
try to tell the meaning of each line by the number of elements of
each line list and the its position in the file. But it is
definitely not the way Python should be used.

Any ideas on how to implement a more elegant yet efficient python
version?

Thanks.



-- 
~ying



More information about the Python-list mailing list