By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,598 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,598 IT Pros & Developers. It's quick & easy.

how to make a paragraph from file to file

P: 12
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
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: 29
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.
Nov 7 '08 #2

P: 12
hmmmm,can you show the code please thanks!!!
Nov 8 '08 #3

bvdet
Expert Mod 2.5K+
P: 2,851
It's quite basic:
Expand|Select|Wrap|Line Numbers
  1. data = open('data.txt').read()
  2. print ' '.join(data.split('\n'))
To write to another file:
Expand|Select|Wrap|Line Numbers
  1. f = open('data1.txt', 'w')
  2. f.write(' '.join(data.split('\n')))
  3. f.close()
Nov 8 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.