From 2ad0afec614ca1ede529649ade073ffde681441c Mon Sep 17 00:00:00 2001 From: XiongNeng Date: Thu, 17 Sep 2015 23:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A35.2=E5=B0=8F=E8=8A=82?= =?UTF-8?q?=E7=9A=84bug~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cookbook/c05/p02_print_tofile.py | 2 +- source/c05/p02_printing_to_file.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/c05/p02_print_tofile.py b/cookbook/c05/p02_print_tofile.py index 10896b9..30bd38d 100644 --- a/cookbook/c05/p02_print_tofile.py +++ b/cookbook/c05/p02_print_tofile.py @@ -7,7 +7,7 @@ Desc : def print_tofile(): - with open('somefile.txt', 'rt') as f: + with open('d:/work/test.txt', 'wt') as f: print('Hello World!', file=f) if __name__ == '__main__': diff --git a/source/c05/p02_printing_to_file.rst b/source/c05/p02_printing_to_file.rst index 0584924..8efc229 100644 --- a/source/c05/p02_printing_to_file.rst +++ b/source/c05/p02_printing_to_file.rst @@ -16,12 +16,12 @@ .. code-block:: python - with open('somefile.txt', 'rt') as f: + with open('d:/work/test.txt', 'wt') as f: print('Hello World!', file=f) ---------- 讨论 ---------- 关于输出重定向到文件中就这些了。但是有一点要注意的就是文件必须是以文本模式打开。 -如果文件时二进制模式的话,打印就会出错。 +如果文件是二进制模式的话,打印就会出错。