python,如何使用自定义函数来写进另一个文件
发布网友
发布时间:2022-04-27 13:24
我来回答
共1个回答
热心网友
时间:2022-04-18 21:12
with无问题,你的open省略了模式后,默认为读r,当然没法写了。
open(name[, mode[,
buffering]])
Open a file, returning an object of the file
type described in section File Objects. If the file
cannot be opened, IOError
is raised. When opening a file, it’s preferable to use open()
instead of invoking the file constructor directly.
The first two arguments are the same as for stdio‘s fopen():
name is the file name to be opened, and mode is a string
indicating how the file is to be opened.
The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating
the file if it already exists), and 'a' for appending (which on some Unix systems
means that all writes append to the end of the file regardless of the
current seek position). 【If mode is omitted, it defaults to 'r'.】