[Tutor] How to parse InputFile to generate OutputFile?

Kent Johnson kent37 at tds.net
Thu Sep 18 03:22:54 CEST 2008

On Wed, Sep 17, 2008 at 5:08 PM, Kamisetty, Rajendra
<rkamisetty at paypal.com> wrote:
> Hi,
> I am new to Python and need your help to generate an output file as
> explained below.
> I need to generate an output text file based on the input text file data .
>  Input.txt contents:
> ('146 - Message', '02 - Primary Account Number is: 6751469991140620','10 -
> System Trace Audit Number2: 369325', 'FF47 - Security of the Internet: ')

> 1. Parse the input file to get the value (bold) appears next to string
> "System Trace Audit Number2".

If that is really all you need then a regular expression search could
do it. If you need more data from the input then some sort of parser
might be the easiest solution, perhaps using pyparsing.

> 2. Replace the value (bold) with database equivalent eg. 369325=092222257UXT

The DB-API specification tells generally how to interface to a
database. Some specifics depend on the particular database.

> 3. Generate the output file as below where everything is constant except
> bold text which is databse equivalent of parsed value from input file.

The output doesn't look very constant to me.

If you can show what you have tried and tell us where you are stuck we
can better help you.


More information about the Tutor mailing list