【发布时间】:2014-12-20 15:49:14
【问题描述】:
您好,刚刚从书中复制了这行代码:“think python”(我将文件名从 'book.tex' 编辑为 'words.txt'
import os
filename = 'words.txt'
cmd = ' md5sum ' + filename
fp = os.popen(cmd)
res = fp.read()
stat = fp.close()
在书中:
>>> print res
1e0033f0ed0656636de0d75144ba32e0 book.tex
>>> print stat
None
但对我来说:
>>> print res
>>> print stat
1
为什么会发生这种情况(打印资源打印空白行,打印统计打印 1)
【问题讨论】:
-
它对我有用;你确定你有一个
md5sum命令并且words.txt存在吗? -
@ReutSharabani:
fp.close()不会返回退出代码。 -
为我工作,你确定文本文件真的存在吗?
-
@MartijnPieters 认为是的,现在阅读
-
您使用的是什么版本的 Python?我永远无法让
stat等于1。