Sara Sara - 1 year ago 64
Python Question

Copying some data of a file and pasting it to another file in python

I have a file, where I want to copy some data of the file and paste it to another file, for example suppose a file contains the following data:

AlphaforBravo007 102000000010170000000001 SusanaForCharlie 1000 end

From the above text I want to copy
respectively and paste it to a new file, each on new row.

I would really appreciate any hint.

Answer Source
with open('file1.txt') as f1,open('file2.txt','w') as f2:
 for line in f1: 
   x=line.split()   #now x is ['AlphaforBravo007', '102000000010170000000001', 'SusanaForCharlie', '1000', 'end']

now file2.txt contains:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download