【发布时间】:2016-05-22 15:37:32
【问题描述】:
import os
ot = os.popen("%s") %"ls"
TypeError: unsupported operand type(s) for %: 'file' and 'str'
我无法弄清楚为什么会发生错误。我的意思是它是纯字符串操作,对吧?任何帮助都将不胜感激。
【问题讨论】:
-
您的意思是
os.popen("%s" % "ls")?你现在尝试将%应用于os.popen("%s")(因此错误中出现''file'')和"ls"(''str'')的结果。这和 Bash 有什么关系?! -
ls是文件名还是你想在bash中执行并在这里得到结果的命令?
-
你说得对,%str应该在"%s"之后触摸,不能分开或者报错...