I'm trying to run the following in my C#/IronPython:
import re
Message = re.sub(r"^EVN\|A\d+", "EVN|A08", Message, flags=MULTILINE)
This works fine on real python at the command prompt. However, once I put it into IronPython I get an error:
IronPython.Runtime.PythonContext.InvokeUnaryOperator(CodeContext context, UnaryOperators oper, Object target, String errorMsg)
at IronPython.Runtime.Operations.PythonOps.Length(Object o)
at IronPython.Modules.Builtin.len(Object o)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)
Research led me to understand (right or wrong?) that the MULTILINE flag triggers Compile() in IronPython. Then I found this article about its lack of support in IronPython: https://ironpython.codeplex.com/workitem/22692.
Removing flags=MULTILINE
fixes the error. However, It doesn't match on "^EVN"
any longer.
EDIT: If I use flags=re.MULTILINE
I receive this error:
ERROR Error while processing the message. Message: sub() got an unexpected keyword argument 'flags'. Microsoft.Scripting.ArgumentTypeException: sub() got an unexpected keyword argument 'flags'
END EDIT
My question is: How can I work around this issue and still get the same results I would get at the command line given the above code snippet, but in IronPython?
I rarely use Python, let alone IronPython, so please be forgiving as I'm not sure of my alternatives.