Well...it looks like I do not know how to use it. Could You help me

Example file_1:
====================================================================
20 53 2.66196
21 53 2.67512
20 52 2.63444
21 52 2.94148
====================================================================

Example file_2:
====================================================================
20 53 1.75904
21 53 2.92742
20 52 2.79653
21 52 2.12499
====================================================================

and so on....

my script:
====================================================================
import glob
{some code here}
####here is loop which change folder_daty, zmienna and folder_serw:##########

    plik2=folder_daty+zmienna+"XYZ.txt"
    zbiorcze = folder_serw + zmienna + ".txt"
    if not os.path.isfile(zbiorcze):
        shutil.copy(plik2, zbiorcze)
    else:
        with open(zbiorcze, "wb") as w:
            writer = csv.writer(w)
            for f in glob.glob(plik2):
                rows = open(f, "rb").readlines()
                writer.writerows(rows)
====================================================================


and result looks like:
====================================================================
2,0, ,5,3, ,2,.,4,4,8,2,"
"
2,1, ,5,3, ,3,.,0,4,9,9,6,"
"
2,0, ,5,2, ,3,.,1,8,4,9,5,"
"
2,1, ,5,2, ,3,.,3,2,2,6,5,"
"
====================================================================



Hello,

If the files are not too big, you could do something like:
with open("/home/me/Desktop/test.csv", "wb") as w:
    writer = csv.writer(w)
    for f in glob.glob("/home/me/Desktop/files/*.txt"):
        rows = open(f, "rb").readlines()
        writer.writerows(rows)
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


------------------------------------------------------------------------
*From:* Mateusz K <[email protected]>
*To:* [email protected]
*Sent:* Sat, March 26, 2011 10:08:43 PM
*Subject:* [Tutor] how to join two text files ?

Hello,

I have many text files, where data is delimited by space.
Each file contain three colums: coordinate x, coordinate y and value for this location.

I would like to join this data to get one big file which will contain columns: coordinate x, coordinate y, value1,value2,..., value_n and save it to another text file.

I wrote script, but there's some stupid error (like "\n" character although
I have added .rstrip() command).

Coul You tell me what is most convenient way to join this data
(maybe by using csv module?)?

=========
Best regards,
Mateusz

_______________________________________________
Tutor maillist  - [email protected] <mailto:[email protected]>
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


--
------------------------------------------------------------------------
*Pozdrawiam / Best regards, *
Mateusz Ke;dzior | environmental engineer


Uz.ywam "otwartych" <http://pl.wikipedia.org/wiki/OpenDocument> formatów plików biurowych


environmental protection:
please consider the environment before printing my email

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to