Copying the data

In this section, we will see how we can copy files using the shutil module. For that, first, we will create a hello.py file and write some text in it.

hello.py:

print ("")
print ("Hello World ")
print ("Hello Python ")

Now, we will write the code for copying into the shutil_copy_example.py script. Write the following content in it:

import shutil
import os
shutil.copy('hello.py', 'welcome.py')
print("Copy Successful")

Run the script as follows:

$ python3 shutil_copy_example.py

Output:
Copy Successful

Check the presence of the welcome.py script and you will find the contents of hello.py are copied successfully in welcome.py.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset