使用这个:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
"C:\\Documents and Settings\\[USER]\\Application Data"
Run Code Online (Sandbox Code Playgroud)
如何获取所有用户的根目录?即:
"C:\\Documents and Settings\\[USER]\\"
Run Code Online (Sandbox Code Playgroud) 我想将 Python 与 C# 集成。我发现了两种使用进程间通信和 IronPython 的方法
进程间通信需要在所有客户端计算机上安装 Python.exe,因此不是一个可行的解决方案。
我们开始使用 IronPython,但它现在只支持 2.7 python 版本。我们使用的是 3.7 版本。
以下代码我们尝试使用 IronPython:
private void BtnJsonPy_Click(object sender, EventArgs e)
{
// 1. Create Engine
var engine = Python.CreateEngine();
//2. Provide script and arguments
var script = @"C:\Users\user\source\path\repos\SamplePy\SamplePy2\SamplePy2.py"; // provide full path
var source = engine.CreateScriptSourceFromFile(script);
// dummy parameters to send Python script
int x = 3;
int y = 4;
var argv = new List<string>();
argv.Add("");
argv.Add(x.ToString());
argv.Add(y.ToString());
engine.GetSysModule().SetVariable("argv", argv);
//3. redirect output
var …Run Code Online (Sandbox Code Playgroud)