Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to build Object for List data

17 views
Skip to first unread message

moonhkt

unread,
Oct 8, 2012, 12:10:51 PM10/8/12
to
Hi All

I have Data call FM01. Each format have F1.. F50 Fields. And Global
Program G1..Gn.

The format like below as text file

FM01

Fld # Field Validation
1 F1 N/A
2 F2 N/A
3 F3 Program1,1,2,3 # Add F1 and F2 value to F3
4 F4 Program2,1,3,4 # Add F1 and F3 value to F4
...
50


Seq validation
1 Program3,1,3,4 # max(F1,F3) to F4
......
n
How to using python to Read the text file, Build the data as object
class ?

moonhkt

Laszlo Nagy

unread,
Oct 8, 2012, 2:50:31 PM10/8/12
to pytho...@python.org
>
> Seq validation
> 1 Program3,1,3,4 # max(F1,F3) to F4
> ......
> n
> How to using python to Read the text file, Build the data as object
> class ?
Open the file using the open() command. Then iterate over the lines
within a stateful algorithm that parses the lines with regular expressions.

What did you try so far?

Joel Goldstick

unread,
Oct 8, 2012, 3:13:44 PM10/8/12
to Laszlo Nagy, pytho...@python.org
On Mon, Oct 8, 2012 at 2:50 PM, Laszlo Nagy <gan...@shopzeus.com> wrote:
>>
>> Seq validation
>> 1 Program3,1,3,4 # max(F1,F3) to F4
>> ......
>> n
>> How to using python to Read the text file, Build the data as object
>> class ?
>
> Open the file using the open() command. Then iterate over the lines within a
> stateful algorithm that parses the lines with regular expressions.

before you go the regex route try str.split() since it looks like your
columns are separated by tabs or spaces. You could also look into csv
package.

>
> What did you try so far?
> --
> http://mail.python.org/mailman/listinfo/python-list



--
Joel Goldstick
0 new messages