How to copy the contents of a file to another file with python
This article mainly introduces how to use python to copy the contents of a file to another file related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this article on how to use python to copy file contents to another file will have a harvest, let's take a look at it.
The specific code is as follows:
1. Define two files and open them.
2. Use the read () function to read the file1 file.
3. Use the write () function to write content.
4. Finally, use the close () function to close the file.
#! / usr/bin/python
#-*-coding: utf-8-*-
# www.xieniao.com
File1 = open ("file1.txt", "r")
File2 = open ("file2.txt", "w")
S = file1.read ()
W = file2.write (s)
File1.close ()
File2.close ()
This is the end of the article on "how to use python to copy the contents of a file to another file". Thank you for reading! I believe you all have a certain understanding of "how to use python to copy the contents of a file to another file". If you want to learn more, you are welcome to follow the industry information channel.