Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to copy the contents of a file to another file with python

Shulou Source: shulou.com Published: 2022-05-31 11:12:46 09月11日 Update

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.

Tags: Documents content functions knowledge articles two code value easy to operate articles easy to understand more read industry information information channels channels utf-8 learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi Huawei Apple Linux