匿名用户
1级
2016-01-27 回答
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'.】
追问:
with open('man_data.txt') as mf :
原来您说的是这里。
可是man_data.txt文件我又不动啊?
追答:
open("man_data.txt","w“)不久可以了吗?
追问:
从新来个例子:
data = open("case.txt")
比如case.txt里面是['a', 'b', 'c']我想把case里的文件复制到case2.txt中,并且这样显示:
a
b
c如何写print_lol语句啊?