Domanda

Sto costruendo un sito ASP.NET MVC (C #), dove Voglio realizzare STV ( voto unico trasferibile ) di voto . Ho usato OpenSTV per gli scenari di voto prima, con grande successo, ma non ho mai usato a livello di codice.

Il href="http://code.google.com/p/stv/wiki/script16" rel="nofollow noreferrer" title="Python sceneggiatura OpenSTV Google Code project offre un script Python che permette l'utilizzo di OpenSTV da altre applicazioni:

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()

C'è un modo per me di fare una tale chiamata Python dal mio sito C # ASP.NET MVC?

Se sì, come?

Grazie in anticipo!

È stato utile?

Soluzione

Ecco è un buon esempio su come chiamare IronPython da C #, compresi passare argomenti e alla ricerca; Naturalmente dovrete fare quel codice in una funzione, con ballotFname e reportFname come i suoi argomenti.

Altri suggerimenti

Il modo migliore è probabilmente quello di utilizzare IronPython. Vedere questa risposta per un punto di partenza.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top