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

Y

Ying Zu

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.
meaning of each line by counting the number of elements
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top