python - 当我从 c# 运行它时,为什么 python 无法识别文本文件?
问题描述
有问题的代码:
```
def loadNumbers(file="ClientNumbers.txt"):
numbersFile = open(file)
numbers = numbersFile.readlines()
return numbers
```
从我的 python IDE 运行此代码时,它工作正常。但是,当我使用 C# 中的系统诊断程序运行 python 脚本时,我收到 ClientNumbers.txt 不是现有文件或目录的错误。
C#代码:
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Users\francois\AppData\Local\Programs\Python\Python38-32\python.exe";
start.Arguments = @"..\..\python\sender.py";
start.UseShellExecute = false;
start.CreateNoWindow = true;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
start.LoadUserProfile = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string stderr = process.StandardError.ReadToEnd();
string result = reader.ReadToEnd();
Console.WriteLine("success from c#");
Console.WriteLine(result);
Console.WriteLine(stderr);
}
}
这背后有什么原因吗?
我尝试移动文本文件并相应地调整路径,但没有成功。
C# 应用程序和 python 脚本位于一个文件夹内的不同子文件夹中。
调用 loadNumbers 方法并将其分配给变量: number= loadNumbers()
这是程序停止并给我文件未找到错误的地方
解决方案
推荐阅读
- amazon-web-services - Runway X Serverless Framework:使用 Runway for CICD 从无服务器仪表板使用环境变量进行部署
- spring-boot - 如何优雅地关闭 Spring Boot 应用程序
- java - 如何在 JSON 数组中发送特定数据
- python - 使用 lambda 的阶乘函数
- javascript - 如何为具有 javascript 值的选择框制作占位符?
- java - 如何在Android中制作和处理将json文件作为响应的Http请求?
- python - 如何将 pandas DataFrame 转换为计数表?
- excel - 根据位置重新排列单元格内容
- python - 如何在不包含无的情况下单行打印数据框?
- reactjs - cartItems 数组和 localStorage 未更新