Reputation: 437
I've got an interface and an abstract base class in C# 4.0:
public interface IScript
{
ScriptResources Resources { get; set; }
string MessageLog { get; }
void Init();
ScriptResult Execute();
void Cleanup();
}
public abstract class Script : IScript
{
public ScriptResources Resources { get; set; }
public string MessageLog { get; protected set; }
public abstract void Init();
public ScriptResult Execute()
{
try
{
Init();
ScriptResult = RunScript();
}
finally
{
Cleanup();
}
return ScriptResult;
}
protected abstract ScriptResult RunScript();
public abstract void Cleanup();
}
On the IronPython side, I've got the following class which inherits from the C# Script class:
import clr
clr.AddReference("MyCSharpLibrary.dll")
from MyCSharpLibrary import *
class IronPythonScript(Script):
def __new__(self):
return Script.__new__(self)
def __init__(self):
return Script.__init__(self)
def Init(self):
Script.LogMessage(self, "< IronPython: Init() >")
Script.LogMessage(self, "")
# Do stuff
def RunScript(self):
Script.LogMessage(self, "< IronPython: RunScript() >")
# Do stuff
def Cleanup(self):
Script.LogMessage(self, "< IronPython: Cleanup() >")
# Do stuff
However, in order to use the base class Script properties (MessageLog, Resources) in IronPython I have to use the following rather ugly syntax which seems wrong to me:
Script.MessageLog.__set__(self, "TEST VALUE")
print Script.MessageLog.__get__(self)
What am I doing wrong? (note: I have limited experience with Python)
Upvotes: 0
Views: 681
Reputation: 796
how about:
self.MessageLog = "TEST VALUE"
print self.MessageLog
Upvotes: 1