Ich verwende Visual Studio 12, um Formulare mit C# zu erstellen. Es ist mir gelungen, ein Argument von C# nach Python zu übergeben. Ich verwende keine Iron Python. Die neue Anwendung, an der ich arbeite, muss zwei Argumente an Python übergeben. Beide Argumente sind Daten, die der Benutzer auswählt. Übergeben von zwei Argumenten (Daten) von C# an ein Python-Skript
Dies ist mein Code, um die Argumente zu erfassen und an Python zu übergeben.
private void button1_Click(object sender, EventArgs e)
{
dbegin = PublicVars.g_begindate;
dend = PublicVars.g_enddate;
CallPython python = new CallPython(@"C:\Python27\ArcGIS10.3\python.exe");
python.Run_Script(@"\\gisdb01\gis\tools\Python\TA_Report\Update_4_Road.pyc", dbegin dend);
this.Close();
}
private void dateTimePickerBegin_ValueChanged(object sender, EventArgs e)
{
PublicVars.g_begindate = dateTimePickerBegin.Text;
}
private void dateTimePickerEnd_ValueChanged(object sender, EventArgs e)
{
PublicVars.g_enddate = dateTimePickerEnd.Text;
Was passiert, ist die 'dend' Fehler Highlights und gibt mir ") erwartet". Ich habe versucht, hinzuzufügen und Kommas zwischen Dbegin und Dend, aber kann nicht scheinen, um dies zu arbeiten.
Dies ist der Code Ich benutze Python Call:
namespace Advisory_Application
{
class CallPython
{
string pythonLocationString;
public CallPython(string pythonLocation)
{
pythonLocationString = pythonLocation;
}
public void Run_Script(string scriptPathName, string arguments)
{
int ExitCode;
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = pythonLocationString;
processStartInfo.Arguments = scriptPathName;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.CreateNoWindow = true;
Process updateProcess = Process.Start(processStartInfo);
updateProcess.WaitForExit();
ExitCode = updateProcess.ExitCode;
updateProcess.Close();
}
}
}
Jede Hilfe würde geschätzt.
Das hat super funktioniert, gibt es keine Fehler in C#! –