how to make a paragraph from file to file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndoe
    New Member
    • Sep 2007
    • 12

    how to make a paragraph from file to file

    how to make a paragraph from file to file

    like this e.g data.txt

    i
    want
    eat
    some
    pizza
    with
    cappucino
    in
    kuta
    bali



    to this data2.txt

    i want eat some pizza with cappucino in kuta bali

    but without exchange the code i free change data.txt

    e.g

    i
    want
    eat
    some
    pizza
    with
    cappucino
    in
    kuta
    bali
    late
    night

    i want eat some pizza with cappucino in kuta bali late night
  • Fabez
    New Member
    • Oct 2008
    • 29

    #2
    First you will need to open the first file and concatanate it into a string line by line. Then you will need to write this string to your second file.

    Comment

    • ndoe
      New Member
      • Sep 2007
      • 12

      #3
      hmmmm,can you show the code please thanks!!!

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        It's quite basic:[code=Python]data = open('data.txt' ).read()
        print ' '.join(data.spl it('\n'))[/code]To write to another file:[code=Python]f = open('data1.txt ', 'w')
        f.write(' '.join(data.spl it('\n')))
        f.close()[/code]

        Comment

        Working...