Is there any way to append the content of file1 to the beginning of file2? I tried using this method but it doesn't seem to work
def main():
"""The program does the following:
- it inserts all the content from file2.txt to the beginning of file1.txt
Note: After execution of the your program, only file1.txt is updated, file2.txt does not change."""
#WRITE YOUR PROGRAM HERE
#Call the main() function
if __name__ == '__main__':
main()
f = open('file1.txt', 'r')
f1 = open('file2.txt', 'r')
def insert(file2, string):
with open('file2.txt','r') as f:
with open('file1.txt','w') as f1:
f1.write(string)
f1.write(f.read())
os.rename('file1.txt',file2)
# closing the files
f.close()
f1.close()