[Tutor] handling a textfile

Fidel Sanchez-Bueno fidellira.6 at gmail.com
Wed Aug 19 10:12:23 CEST 2009


Olli Virta escribió:
> Hi!
>  
> I have a textfile (job.txt) that needs modifying. The structure of 
> this file is like this:
>  
> AAA1...
> BBB1...
> CCC1...
> AAA2...
> BBB2...
> CCC2...
> etc...
>  
>  
>  
> Question is how can I turn this all to a textfile (done.txt) that is 
> suppose to look like this:
>  
> AAA1...BBB1...CCC1...
> AAA2...BBB2...CCC2...
> etc.
>  
> Thanks! OV
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
hi...

i dont think this is the best way of doing it, but you can have an idea 
by reading the code:

some_file="""AAA1...
BBB1...
CCC1...
AAA2...
BBB2...
CCC2..."""

some_tuple=some_file.split()

def change(some_tuple):
    temp=""
    temp2=""
    for x in some_tuple:
        if "1" in x:
            temp+=x
        else:
            temp2+=x
    done= temp +"\n" +temp2
    return done

done_file=change(some_tuple)

is not perfect but you can get the idea..


More information about the Tutor mailing list