Swap file using python

Swap the two files lines from one to one using python... 

Input:

create two text files

Output:

Interchange the lines of two file. 
(i.e.,) sample.txt file lines is stored to sample2.txt file
and sample2.txt file lines is stored to sample.txt file

Program:

for python 3...

a=open("sample.txt")
x=a.read()
print(x)
a.close()

b=open("sample2.txt")
y=b.read()
print(y)
b.close()

c=open('sample.txt','w')
c.write(y)
print(c)
c.close()

d=open('sample2.txt','w')
d.write(x)
print(d)
d.close()

--------------------------------------------------------------------------------

Comments

Popular posts from this blog

PyCon-India 2019

Addition Game using Python