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

Discussion in 'Python' started by Ying Zu, Jan 8, 2011.

  1. Ying Zu

    Ying Zu Guest

    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
    Ying Zu, Jan 8, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rocky Moore
    Replies:
    7
    Views:
    1,715
    mikeb
    Jan 14, 2004
  2. =?iso-8859-15?Q?Jens_M=FCller?=

    Pre defined value for <input type="file">

    =?iso-8859-15?Q?Jens_M=FCller?=, Sep 7, 2006, in forum: HTML
    Replies:
    4
    Views:
    955
    David Dorward
    Sep 7, 2006
  3. Oodini
    Replies:
    1
    Views:
    1,750
    Keith Thompson
    Sep 27, 2005
  4. Juha Nieminen
    Replies:
    3
    Views:
    1,129
    Juha Nieminen
    Feb 22, 2008
  5. Ying Zu
    Replies:
    1
    Views:
    173
    Magnus Lyckå
    Jan 13, 2011
Loading...

Share This Page