January 2019
Beginner
318 pages
8h 23m
English
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\n")print ("Hello Python\n")
Now, we will write the code for copying into the shutil_copy_example.py script. Write the following content in it:
import shutilimport osshutil.copy('hello.py', 'welcome.py')print("Copy Successful")
Run the script as follows:
$ python3 shutil_copy_example.pyOutput: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.
Read now
Unlock full access