[Tutor] compare and arrange file

Edgar Almonte samudhio at gmail.com
Tue Jul 12 02:07:04 CEST 2011


back again david

i do the for because the line is delimited by pipeline so and i need
get the field number 2 and 3 of the line
if i understand well the split('|')[z] will just split till there ( z
value ) so if i do split('|')[2] i will get:
XXXXXXXXX XXXX, 0000000000000.00 and i just want the number value part
of the line

i try putting the read of orig1 inside the fist loop but that don't
see work because the thing is that for some reason the fist loop is
just passing one time ( the first one
if you see in my code i put a print line1 in the first loop and a
print value in the second one and i get something line

"----line1-------"
"value1"
"value1"
"value1"
"value1"
"value1"
"value1"

etc.

pd: sorry for my bad english

On Mon, Jul 11, 2011 at 7:35 PM, Dave Angel <d at davea.name> wrote:
> On 07/11/2011 06:39 PM, Emile van Sebille wrote:
>
> On 7/11/2011 3:16 PM Edgar Almonte said...
>
> hello , i have a file this a structure like this
> XXXXXXXXX XXXX| 0000000000000.00| 0000000088115.39|
> XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00|
> XXXXXXXXX XXXX| 0000000000000.00| 0000000090443.29|
> XXXXXXXXX XXXX| 0000000088115.39| 0000000000000.00|
> XXXXXXXXX XXXX| 0000000000000.00| 0000000088335.39|
> XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00|
> XXXXXXXXX XXXX| 0000000088335.39| 0000000000000.00|
> XXXXXXXXX XXXX| 0000000090443.29| 0000000000000.00|
>
> now i need re-arrange the file in this way:
> XXXXXXXXX XXXX| 0000000000000.00| 0000000088115.39|
> XXXXXXXXX XXXX| 0000000088115.39| 0000000000000.00|
> XXXXXXXXX XXXX| 0000000000000.00| 0000000090453.29|
> XXXXXXXXX XXXX| 0000000090453.29| 0000000000000.00|
>
> etc....
>
> It's not obvious to me for your sample what you want.  For example, the 2nd
> value 0000000090453.29 from the re-arranged group doesn't appear in the top
> sample.
>
> If I venture a guess, it seems to me that you want the debits and
> corresponding offsetting credits listed in sequence.
>
> In pseudo-code, that might me done as:
>
> read lines from file
> for each line in lines
>   set flag to D or C based on values
>   set sortkey to value+flag
>   append sortkey and line to decorated list
> sort decorated list
> for key,line in decorated list
>   print line
>
>
> HTH,
>
> Emile
>
>
>
>
>
> i try this
> http://pastebin.com/2mvxn5GY
> but without look
>
> I also can't see any pattern in the data to give a clue what kind of
> filtering you're trying to do.  A more specific spec would be useful.
>
> I can comment on your pastebin code, however.  You should have pasted it in
> your message, since it's short.
>
> def splitline(line, z):
>     if z == 0:
>        pass
>
>     fields = line.split('|')
>     nlist = []
>     for field in fields:
>         nlist.append(field)
>
>     return nlist[z]
>
> The whole loop with nlist is a waste of energy, as you already got a list
> from split().  You could replace the function with
>    def splitline(line, z):
>          return  line.split('|')[z]
>
> The if z==0 doesn't do anything either.  Perhaps you meant to do some error
> checking in case the line doesn't have at least z fields.
>
> But the real problem in your code is the you posted for loop.  The inner
> loop takes multiple passes through the orig1 file, but the second time won't
> get anything, since the file is already positioned at the end.  I'd simply
> move the open statement inside the outer loop.
>
> There may be other problems, but that could get you going.
>
> DaveA
>
>
>
>
>
>
>
> --
>
> DaveA
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list