- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个非常不幸的情况。 Maya 2011 附带 2.6.4,此代码在其中不起作用:
pipe = subprocess.Popen( 'p4 -G edit C:/somefile.txt', stdout=subprocess.PIPE).stdout
try:
while 1:
record = marshal.load( pipe )
list.append( record )
except EOFError:
pass
各种 2.5 版本都可以使用,最新的 2.6.5 也可以使用,当然不是 Maya 附带的版本!它抛出这个错误:
# Error: TypeError: file <maya console> line 3: marshal.load() arg must be file #
什么是最好的行动方案?
只是为了继续生活,代码被更改为只转储一个文件,这样 marshal.load 就可以加载一个实际的文件。虽然这有效,但它很蹩脚。
Maya 2011 通过 zip 访问 python,因此,作为一个小测试,我压缩了 2.6.5 的 Python26/Lib,并将指向 2.6.4 zip 的 sys.path 条目换成了 2.6.5 zip。虽然我没有对此进行广泛测试,但这似乎有效。我不知道这是比上面那个更好还是更坏的主意。
理想情况下(我认为)我可以在 2.6.4 中做一些事情来完成这项工作,而无需混合 python 版本或一直将临时文件写入磁盘。有什么想法吗?
关于 marshal.loads() 的更新
尝试 marshal.loads(),虽然没有错误,但仍然无法正常工作。我肯定在黑暗中摸索着这些东西。如果文件操作是单独完成的,那么 perforce 的东西慢得无法忍受,必须在一个查询中完成它们。原始代码是这样做的:
files = [a,b,c...n] # Huge list of files
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(fi, pipe) = (p.stdin, p.stdout)
# Fill the command up with all the files
for file in files:
fi.write(file + '\n')
fi.close()
# Get all the results
try:
while 1:
record = marshal.load( pipe )
listData.append( record )
except EOFError:
pass
我不知道为什么会这样(在 2.5.x/2.6.5 中)但确实如此; listData 最终作为所有文件结果的列表。我不知道如何使用 marshal.loads() 执行此操作,我只得到第一个结果。此方法几乎一字不差地取自 perforce所以我知道这是做事的方式。很容易想象,我只是不知道如何正确使用子流程和编码。
更新 2 marshal.loads() 完全有效!
经过更多测试后,pipe.read() 提供了所有数据,但它包含一些空字符或其他我不完全理解的内容,因此 marshal.loads() 只会读取第一个条目。在这种特殊情况下,我可以拆分“{”上的数据并收集数据。
listData = []
results = pipe.read().split("{")
# Skip the first entry since it's empty
for result in results[1:]:
listData.append( marshal.loads( "{" + result) )
感谢 Cristian 为我指明了正确的方向,希望任何使用 perforce 升级到 Maya 2011 的人都能让事情变得更顺利。
最佳答案
使用 -G 选项解码 p4 的输出时遇到同样的问题。 marshal.loads(str)
仅读取第一条记录,marshal.load(StringIO(str))
失败并显示“marshal.load() arg 必须是文件”。我没有使用拆分建议,而是使用了临时文件解决方法:
import subprocess, marshal, tempfile
tempf = tempfile.TemporaryFile()
subprocess.Popen(cmd, stdout=tempf).communicate()
tempf.seek(0)
try:
while 1:
record = marshal.load(tempf)
listData.append( record )
except EOFError:
pass
tempf.close()
请注意,python 会在您关闭临时文件后立即为您删除它。
关于Python 2.6.4 marshal.load 不接受使用 subprocess.Popen 创建的打开文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3249822/
我正在本地编程应用程序,但是当我迁移到服务器时,使用此行出现解析错误: if(!is_array($data[array_keys($data)[0]])) 返回值: Parse error: syn
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我已经开始尝试用 C++ 学习 Winsock,但我遇到了一些问题。我首先遵循 MSDN 上的 Winsock 示例(一个基本的客户端-服务器)。 http://msdn.microsoft.com/
我有一段使用 epoll 的代码,但它有问题。当我运行它时,它给出输出:服务器套接字()没问题......服务器绑定(bind)()没问题......3个4个接受:无效参数 我在 ubuntu lin
我正在寻找一种方法来接受 $_GET 变量作为文件路径,例如 - /page/test将转换为 page.php?page=test .我已经搜索过,但找不到任何可以帮助我的东西,因此我在这里问。 我
我想要一个只接受从 0 到 9 和减号的浮点数的正则表达式。 请帮忙。 最佳答案 ^[-+]?[0-9]*\.?[0-9]+$ ^ - 字符串开头 [-+]? - 0 或 1 符号指示符 [0-9]*
请问如何接受\r\n无需将其更改为 \\r\\n , 与 fgets . 我想让程序翻译 \r\n到换行符而不是将其打印为字符串。 当前代码: char buff[1024]; printf("Msg
我正在编写一个 Cocoa 应用程序,该应用程序需要在其 Dock 图标上接受已安装卷的滴落。它不是基于文档的;我打算将每个卷分派(dispatch)到 application:openFiles 中
我在 SQLite 中发现了这种意外行为。 SQLite 似乎接受 SQL 连接语法中的任意关键字。如果我不小心键入了 natural join 而不是 natural join,则会生成笛卡尔积。这
我在 Windows 窗体的同一个窗体上有一个 TreeView 和一个多行文本框。我有拖放设置,以便我可以将节点从 TreeView 拖到文本框并将文本插入文本框(这是有效的)。 我想增强这一点,以
我正在创建一棵类似于 D3 Layout Tree 的树并尝试绑定(bind)我的自定义 JSON 对象。切换树节点的代码如下。 function toggleAll(d) { if (d.c
所以,我希望能够向我的 DOB 字段发送空选项。 这是我的表单生成器: ->add('birthDate', DateType::class, array( 'widg
错误可以在这里看到:http://djaffry.selfip.com:8080/ 我希望索引页接受参数,无论是 mysite.com/search/param_here 或 mysite.com/?
我想知道标准 Scala 解析器组合器是否包含一个解析器,该解析器接受 Scala 语言本身也接受的相同标识符(如 Scala 语言规范第 1.1 节中所指定)。 StdTokenParsers 特征
我暂时使用以下行在我的 Android 手机上创建 ServerSocket: socketl = new ServerSocket(port, 0, InetAddress.getByName("1
今天早上刚刚发布了一个应用程序,我在所有可能的设备和模拟器上测试了它,但是当我从商店下载它时,应用程序在启动时崩溃。我在很多设备和iOS版本上测试过,但结果都是一样的: Incident Identi
我想要 5 个名字中最长的一个。我想我应该使用 compareTo() 方法或 length()? 输出必须是这样的: enter 5 names : Joey Mark Catherine Zach
抱歉,我不熟悉泛型,我可以创建一个如下所示的泛型类: public class InfoField { } 上面的类可以接受如下值: , User> 但是我可以有接受 map 对象作为值的类吗?
我想让一个单元格等于它上面的单元格。 当我写作时 =address(row()-1;column()) 它只是写入上面单元格的名称(例如,对于 B2,它写入 $B$1) 是否有一个函数可以输入地址并放
我正在使用Asm访问java字节码来获取方法信息。看来ClassReader类的accept方法是异步调用的,所以不可能立即获取方法信息。我该怎么办? 最佳答案 实际上,accept 方法是从您自己的
我是一名优秀的程序员,十分优秀!