contextlib偶尔会失败

时间:2018-08-22 11:29:53

标签: python-3.x macos

我想将帮助文档写入md文件

>>> import re
>>> import contextlib
>>> file = open("regex_help.md", "w")
>>> with contextlib.redirect_stdout(file):
...     help(re)

但是,“ regex_help.md”为空

>>> os.stat("regex_help.md").st_size
0

我记得它昨天工作了。

>>> file.flush()
>>> os.stat("regex_help.md").st_size
1

file.flush()无法正常工作

为什么偶尔会失败?

0 个答案:

没有答案