使用日期時間,我主持我的IronPython在C#web應用程序,像這樣:不能在IronPython的
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
var script = Engine.CreateScriptSourceFromString(pythonCode, SourceCodeKind.Statements);
script.Execute(scope);
而且我的Python代碼如下所示:
import clr
clr.AddReference('System.Core')
from System import DateTime
theDate = DateTime.Today()
產生這個錯誤:
IronPython.Runtime.Exceptions.ImportException: Cannot import name DateTime
我在Google上花了一些時間,並且我發現的大部分代碼似乎都不工作了。
我的IronPython運行時版本是v2.0.50727 - 我應該升級嗎?我以爲DateTime
會從早期的門開始?
它給你的錯誤信息到底是什麼? python是否在屬性上使用括號? (如果沒有,請嘗試'DateTime.Today'。) – 2009-09-24 16:31:54
2.0.50727聽起來像是一個CLR版本號,而不是IronPython版本號,順便說一句。如果你只是運行ipy,會出現什麼版本? – 2009-09-24 16:39:10