我一直在尝试创建一个dict继承的子类,UserDict.DictMixin它支持不可散列的密钥.性能不是问题.不幸的是,Python DictMixin通过尝试从子类创建一个dict对象来实现一些功能.我自己可以实现这些,但我坚持下去__cmp__.
我找不到__cmp__dict类内置使用的逻辑的简洁描述.
请考虑以下代码:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);
ScriptScope scope = engine.CreateScope();
scope.SetVariable("message", "Hello, world!");
string script = @"print message";
ScriptSource source = scope.Engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
source.Execute();
Run Code Online (Sandbox Code Playgroud)
此代码产生以下异常:
Microsoft.Scripting.Runtime.UnboundNameException未处理Message ="name'message'未定义"
我错过了什么?