c#


How to call an IronPython 2 method from C#


I can get an IronPython 2 class back to my C#. What is the new IronPython 2 way of calling a member on that class?
object ironPythonClass = scope.GetVariable("Hamish");
object[] args = new object[0];
object pythonObject = engine.Operations.Call(ironPythonClass, args);
var member = "Home";
// old way IronPython 1
// var methodResult = Ops.Invoke(this.pythonObject, SymbolTable.StringToId(member), args);
I thought all I'd have to do was
var methodResult = PythonOps.Invoke(codeContext, pythonObject, SymbolTable.StringToId(member), args);
but creating a dummy CodeContext doesn't seem to be right. I feel as though I should be able to derive one from my
code.Execute();
that runs the Python file creating the class, plus the scope that arises out of that execution.
Found a way to do it:
var ops = engine.Operations;
var x = ops.GetMember(pythonObject, member);
var h = ops.Call(x, new object[0]);
Looks like the Operations produces an OperationsObject which has useful members.
Looking at the DLR code (Microsoft.Scripting.Hosting) however I see that Call is deprecated:
[Obsolete("Use Invoke instead")]
public object Call(object obj, params object[] parameters) {
return _ops.Invoke(obj, parameters);
}
My version of scripting 0.9.20209, doesn't yet have the Invoke however.
After updating to the newer IronPython 2.6Beta and its scripting dlls I find I can write:
var h = ops.InvokeMember(pythonObject, member, new object[0]);

Related Links

C# Winforms System.Threading.Timer
listbox doesn't show displaymember
How to bring user control front of another one when I click on it
Check if OpenVPN UDP Port is open
DataGridView acting weird… not redrawing leaving weird artifacts behind
Spring.net + NHibernate very slow in server machines
Creating helper method that can be used in LINQ (EF)
Store Excel Sheet data to sql server
Mixing ASP.Net MVC custom routing and partial views in a ASP.Net web forms project
WPF reuse XAML resource
Pack files into one, to later programmatically unpack them [closed]
EasyUi datagrid in Asp?
Extra lines appear when EdgeMode.Aliased option is used in WPF
exec not opening up .exe file
Field property is required. All field web controls require the field name to be set
Must be Placed Inside a Form Tag With runat=server

Categories

HOME
actionscript-3
msbuild
url
teradata
sql-server-2014
mysqli
python-requests
watson-iot
salesforce-lightning
symfony-sonata
swap
comments
hibernate-mapping
software-collections
elastalert
aspectj
ldap-query
mongodb-replica-set
audio-streaming
xna
polybase
dev-c++
ng-tags-input
concatenation
launchd
windows-10-mobile
azure-table-storage
jboss-arquillian
login-required
tikz
jql
directions
epub
angularjs-resource
minitest
gstreamer-1.0
jslider
ng-lightning
socketcluster
tapply
flume-ng
php-mongodb
grails-2.0
inner-join
openidm
e4
playframework-2.3
totalview
rmq
qt3d
blackberry-webworks
mongodb-3.3
strtol
networkstream
altova
nsoperationqueue
diameter-protocol
razorengine
trendline
ios8-share-extension
angular-promise
web-standards
vectordrawable
waterline
opennebula
ultraedit
maven-archetype
firebase-tools
wingdb
backtrace
optimistic-locking
agent-based-modeling
sat4j
fscanf
time-frequency
visual-c#-express-2010
android-relativelayout
cvi
nativequery
logo-lang
node-amqp
wpa
usersettings
gwt2
cloudmade
generator-expression
moonscript
libx264
report-viewer2010
teamsystem
webpage-screenshot
derived-class
custom-cursor
hypertable
php-gettext
mvcmailer
rjs
vectorwise
service-layer
auto-compile
functional-specifications
nbehave
helios
lts
calendarextender
projectgen
httpbrowsercapabilities

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App