Appel Python app / script C #
-
25-09-2019 - |
Question
Je construis un site MVC (C #) ASP.NET où je veux mettre en œuvre STV ( vote unique transférable ) vote . Je l'ai utilisé OpenSTV pour les scénarios de vote avant, avec beaucoup de succès, mais je ne l'ai jamais utilisé un programme.
Le OpenSTV Google Code projet propose un script Python qui permet l'utilisation de OpenSTV d'autres 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()
Est-il possible pour moi de faire un tel appel Python de mon site C # ASP.NET MVC?
Si oui, comment?
Merci d'avance!
Autres conseils
La meilleure façon est probablement d'utiliser IronPython. Voir cette réponse pour un point de départ.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow