Call Python / script application from C #

I am creating an ASP.NET MVC (C #) site where I want to implement STV (Single Transferable Vote) voting . I used OpenSTV for voting scenarios before, with great success, but I never used it programmatically.

OpenSTV. The Google Code project offers a Python script that allows you to use OpenSTV from other applications:

import sys
sys.path.append("path to openstv package")

from openstv.ballots import Ballots
from openstv.ReportPlugins.TextReport import TextReport
from openstv.plugins import getMethodPlugins

(ballotFname, method, reportFname) = sys.argv[1:]

methods = getMethodPlugins("byName")
f = open(reportFname, "w")

try:
    b = Ballots()
    b.loadUnknown(ballotFname)
except Exception, msg:
    print >> f, ("Unable to read ballots from %s" % ballotFname)
    print >> f, msg
    sys.exit(-1)

try:
    e = methods[method](b)
    e.runElection()
except Exception, msg:
    print >> f, ("Unable to count votes using %s" % method)
    print >> f, msg
    sys.exit(-1)

try:
    r = TextReport(e, outputFile=f)
    r.generateReport();
except Exception, msg:
    print >> f, "Unable to write report"
    print >> f, msg
    sys.exit(-1)

f.close()

Is there a way to make such a call to Python from my ASP.NET MVC MVC site?

If so, how?

Thanks in advance!

+1
source share
2 answers

- , IronPython #, ; , ballotFname reportFname .

+4

, , IronPython. . .

+3

All Articles