特牛网址导航

16. 读写文件——Python官网语法摘录_value = ('the answer', 42)-CSDN博客

网友收藏
文章浏览阅读154次。1. open(filename, mode)返回 file object。>>> f = open('workfile', 'w')第一个参数:文件名字符串。第二个参数: ‘r’ 文件只读,‘w’ 只写(已存在的同名文件会被删除), ‘a’ 打开文件追加内容,‘r+’ 打开文件读写。默认为 ‘r’。 ‘b’ 以 binary mode 打开文件,用于所有不包含文本的文件。3. with使用 with 相比等效的 try-finally 代码块要简短得多:with o_value = ('the answer', 42)