- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
此代码在使用 Python 2.5.1 运行时生成“AttributeError: 'Popen' object has no attribute 'fileno'”
代码:
def get_blame(filename):
proc = []
proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE))
proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE)
proc.append(Popen(['tr', r"'\040'", r"';'"], stdin=proc[-1]), stdout=PIPE)
proc.append(Popen(['cut', r"-d", r"\;", '-f', '3'], stdin=proc[-1]), stdout=PIPE)
return proc[-1].stdout.read()
堆栈:
function walk_folder in blame.py at line 55
print_file(os.path.join(os.getcwd(), filename), path)
function print_file in blame.py at line 34
users = get_blame(filename)
function get_blame in blame.py at line 20
proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE)
function __init__ in subprocess.py at line 533
(p2cread, p2cwrite,
function _get_handles in subprocess.py at line 830
p2cread = stdin.fileno()
这段代码应该可以在 python 文档中描述 this usage .
最佳答案
三件事
首先,你的 () 是错误的。
其次,subprocess.Popen()
的结果是一个进程对象,而不是一个文件。
proc = []
proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE))
proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE)
proc[-1]
的值不是文件,而是包含文件的进程。
proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1].stdout, stdout=PIPE))
第三,不要在 shell 中执行所有 tr
和 cut
垃圾操作,几乎没有什么比这更慢的了。用 Python 编写 tr
和 cut
处理 - 它更快更简单。
关于Python子进程 "object has no attribute ' fileno'”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/777996/
需要帮助将这些给定的数字打印成星号,但我是编程新手;我该怎么做? #include int main(void) { int a[5]={20,1,5,15,12}; int i=0
使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息. 我见
我不知道制服在内存中是如何表示的。 制服似乎会占用宝贵的寄存器空间,但它们最终会传入/通过/传出到全局内存中,对吗? 制服不用时情况会发生变化吗?编译器可以将它们优化掉吗?--在这种情况下,我已经将无
我正在尝试在名为“timeclock”的模型上记录“time_in”和“time_out”记录。这是我想做但无法开始工作的事情! 检查最后一个时钟条目,看看它是否同时填充了“time_in”和“tim
我想听听您如何解决这种编程任务!?每种类型(OPER = 1 类型)对应一种特定的信息。 这只是大约 10 个具有相同结构的规范之一。首选创建这些“转换器”(协议(protocol))的通用方法。 最
我正在使用 Rest API(NodeJS、Express)和 PostgreSQL 制作 React-Native 应用。 在我的本地机器上托管时一切正常。当 API 托管在我的机器上并且 Post
我是一名优秀的程序员,十分优秀!