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

Trying to add rows to a Table results in multiple tables
Getting error “Unable to load DLL 'SQLite.Interop.dll'” despite it being in the bin folder
Append data in a json file in C#
C# Foreach loop through json-object, get key [duplicate]
Excel Connectionstring DriverId
BotConnector dynamic field not working: even when a user clicks on one of the buttons in the prompt, the Bot fails to recognize the response
WCF Collection returns empty
Extending interface with new model
How to programmatically get Azure Service Bus Relay details (C#)?
The type or namespace name 'ThreadPoolTimer' could not be found
Join IQueryable with List on object from list
Exporting gridview with paging
Is it possible to pin a text on the top of the console c# [duplicate]
How to read simultaneously by several COM ports
How to delete rows with same value in datagridview
How to passing value to textbox in second form when object has been lunched

Categories

HOME
asterisk
itunesconnect
nltk
azure-resource-manager
snmp
comments
install
subprocess
point-of-sale
camunda
fastreport
github-flavored-markdown
aggregate
sha1
exchange-transport-agents
vivado-hls
jquery-easyui
udeploy
formulas
coccinelle
suitescript
rancher
spock
key-bindings
login-required
loopback
wercker
imdb
jcr
voyager
webmock
headphones
minitest
sdl-2
realloc
scalamock
jquery-inputmask
fisheye
php-mongodb
api-key
amazon-fire-tv
activeandroid
intermediate-language
ajv
fckeditor
easy-thumbnails
require-handlebars
netlink
cosign-api
transaction-isolation
sqlxml
google-finance-api
controlpanel
jts
biginsights
textblob
hexagonal-tiles
xml-simple
polarion
wingdb
pymol
xcode5
uiblureffect
qf-test
javacompiler
livescript
disparity-mapping
dotcmis
serializer
dateadd
smartxls
traceur
iwork
facebook-java-api
logo-lang
xcode6.1-gm-seed
dylan
oc4j
forward-declaration
pudb
servicemanager
setcookie
mail-gem
motordriver
netzke
derived-class
jquery-1.8
databus
nude.js
eeprom
advanceddatagrid
session-hijacking
xpolog
windows-xp-embedded
auto-compile
netduino
meego-harmattan
browser-state
linq-to-mysql
carbon-emacs
appointment
pkcs#7
calendarextender
asp.net-1.1

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