Python.net 没有从 .net 接收到正确的编码字符串
Python.net is not receiving correct encoded string from .net
我正在使用 .net 4.7.1 控制台程序与 python.net 对话,VS2017 报告为版本 2.5.1.0(运行时间版本 v4.0.30319)Python 代码是在 3.6
python:
def ping(input):
if (input == 'ping'):
return 'pong'
return 'invalid'
def headervalid(header):
if (header == '@\n\u001e\rANSI '):
return True
return False
if __name__ == '__main__':
input = '@\n\u001e\rANSI '
print(headervalid(input))
input = 'ping'
print(ping(input))
点网:
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = np.cos(5) + sin(5);
Console.WriteLine(c);
dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);
dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);
Console.WriteLine(a * b);
dynamic parsers = Py.Import("newworld_parsers.bridgetest");
string input = "ping";
var result = parsers.ping(input);
Console.WriteLine(result);
input = @"@\n\u001e\rANSI ";
result = parsers.headervalid(input);
Console.WriteLine(result);
Console.WriteLine("=======");
Console.ReadLine();
}
python 独立 运行 报告:
True
pong
Press any key to continue . . .
点网 运行 报告:
1.0
-0.9589242746631385
-0.675262089199912
float64
int32
[ 6. 10. 12.]
pong
False
=== Press any key to continue ====
注意 python 中的 True 与从 C# 调用时的 False
来自 dot net 的 headervalid() 中的特殊字符似乎没有正确显示。我应该怎么做才能解决这个问题?非常感谢任何想法!
在 C# 字符串前面放置“@”字符会将其转换为原始字符串,这意味着内部没有转义序列将起作用。
您可以通过在代码中添加 Console.WriteLine(input);
来查看。
我正在使用 .net 4.7.1 控制台程序与 python.net 对话,VS2017 报告为版本 2.5.1.0(运行时间版本 v4.0.30319)Python 代码是在 3.6
python:
def ping(input):
if (input == 'ping'):
return 'pong'
return 'invalid'
def headervalid(header):
if (header == '@\n\u001e\rANSI '):
return True
return False
if __name__ == '__main__':
input = '@\n\u001e\rANSI '
print(headervalid(input))
input = 'ping'
print(ping(input))
点网:
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
Console.WriteLine(np.cos(np.pi * 2));
dynamic sin = np.sin;
Console.WriteLine(sin(5));
double c = np.cos(5) + sin(5);
Console.WriteLine(c);
dynamic a = np.array(new List<float> { 1, 2, 3 });
Console.WriteLine(a.dtype);
dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
Console.WriteLine(b.dtype);
Console.WriteLine(a * b);
dynamic parsers = Py.Import("newworld_parsers.bridgetest");
string input = "ping";
var result = parsers.ping(input);
Console.WriteLine(result);
input = @"@\n\u001e\rANSI ";
result = parsers.headervalid(input);
Console.WriteLine(result);
Console.WriteLine("=======");
Console.ReadLine();
}
python 独立 运行 报告:
True
pong
Press any key to continue . . .
点网 运行 报告:
1.0
-0.9589242746631385
-0.675262089199912
float64
int32
[ 6. 10. 12.]
pong
False
=== Press any key to continue ====
注意 python 中的 True 与从 C# 调用时的 False 来自 dot net 的 headervalid() 中的特殊字符似乎没有正确显示。我应该怎么做才能解决这个问题?非常感谢任何想法!
在 C# 字符串前面放置“@”字符会将其转换为原始字符串,这意味着内部没有转义序列将起作用。
您可以通过在代码中添加 Console.WriteLine(input);
来查看。