Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to read ansic file into a pre-defined class?

Reply
Thread Tools

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

 
 
Ying Zu
Guest
Posts: n/a
 
      01-08-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.
meaning of each line by counting the number of elements
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to read ansic file into a pre-defined class? Ying Zu Python 1 01-13-2011 06:23 PM
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
file.read() doesn't read the whole file Sreejith K Python 24 03-24-2009 12:20 PM
Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file. Tony Perl Misc 5 04-19-2004 03:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57