Skip to content

Commit 2ad0afe

Browse files
committed
修正5.2小节的bug~
1 parent b2df706 commit 2ad0afe

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cookbook/c05/p02_print_tofile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def print_tofile():
10-
with open('somefile.txt', 'rt') as f:
10+
with open('d:/work/test.txt', 'wt') as f:
1111
print('Hello World!', file=f)
1212

1313
if __name__ == '__main__':

source/c05/p02_printing_to_file.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
.. code-block:: python
1818
19-
with open('somefile.txt', 'rt') as f:
19+
with open('d:/work/test.txt', 'wt') as f:
2020
print('Hello World!', file=f)
2121
2222
----------
2323
讨论
2424
----------
2525
关于输出重定向到文件中就这些了。但是有一点要注意的就是文件必须是以文本模式打开。
26-
如果文件时二进制模式的话,打印就会出错。
26+
如果文件是二进制模式的话,打印就会出错。
2727

0 commit comments

Comments
 (0)