【发布时间】:2012-07-12 18:14:26
【问题描述】:
我无法在 Python 中加载一个在 IronPython 中转储的泡菜。
当我在 IronPython 中腌制像“[1,2,3]”这样的基本内容时,腌菜在 Python 中加载得很好。但是,当我在 IronPython 中从下面的 DB 查询中提取结果时,尝试在 Python 中加载 pickle 时出现错误“No module named clr”。
可能出了什么问题? (有没有更好的方法在 Python 和 IronPython 之间共享数据?)
def GetData(id):
TheConnection = SqlClient.SqlConnection("server=MyServer;database=MyDB;Trusted_Connection=yes")
TheConnection.Open()
sqlcommand = "MyStoredProcedure#GetMyData '%s'" %id
MyAction = SqlClient.SqlCommand(sqlcommand, TheConnection)
MyReader = MyAction.ExecuteReader()
results = list()
while MyReader.Read():
row = {
'Type':'LolCat',
'Date':datetime.datetime(MyReader[1]),
'Location':str(MyReader[3]),
'Weight':float(MyReader[6])/float(MyReader[7]),
}
results.append(row)
TheConnection.Close()
MyReader.Close()
return results
results1 = GetData(1234)
results2 = GetData(2345)
...
picklefile= open("testpickle","w")
cPickle.dump((results1,results2),picklefile)
...
picklefile = open("testpickle","r")
p = cPickle.load(file) # this is the line that gives the error "ImportError: No module named clr"
【问题讨论】:
-
看起来您的 IronPython 安装可能安装了模块
clr而您的 Cpython 安装没有。 -
没错。 CLR 是 .NET 特定的,不能作为常规 Python 的一部分使用。
-
它看起来都是原始类型,所以应该没有问题。如果可能的话,你能在ironpython.codeplex.com/WorkItem/Create 上打开一个问题并附上泡菜文件吗?我想知道涉及到哪些类型。
标签: python clr ironpython pickle importerror