File copy in python

Description

Python Program to Copy the contents of one file to another file

Solution

file1=open("sample.txt",'r')
file2=open("sample1.txt",'w')
content=file1.read()
file2.write(content)
file1.close()
file2.close()

Explanation

open the source file file1 in read mode
open the destination file file2 in write mode
read the contents of file1 and store it in variable content.
Write content into file2, then close both the files file1 and file2.



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution

Related Programs