我在PyInstaller和Py2exe上遇到了同样的问题,所以我遇到了来自cx-freeze的FAQ上的解决方案。从控制台或作为应用程序使用脚本时,以下功能将为您提供“执行路径”,而不是“实际文件路径”:print(os.getcwd())print(sys.argv[0])print(os.path.dirname(os.path.realpath('__file__')))资料来源:http ://cx-freeze.readthedocs.org/en/latest/faq.html您的旧行(最初的问题):def read(*rnames):return open(os.path.join(os.path.dirname(__file__), *rnames)).read()使用以下代码段替换您的代码行。def find_data_file(filename): if getattr(sys, 'frozen', False): # The application is frozen datadir = os.path.dirname(sys.executable) else: # The application is not frozen # Change this bit to match where you store your data files: datadir = os.path.dirname(__file__) return os.path.join(datadir, filename)使用上面的代码,您可以将应用程序添加到os的路径中,可以在任何地方执行它,而不会出现应用程序无法找到其数据/配置文件的问题。用python测试过:3.3.42.7.13
1 回答

holdtom
TA贡献1805条经验 获得超10个赞
完全按照您的编码将Unicode字符串'\xff'转换为UTF-8字节序列b'\xc3\xbf'。
如果要发送字节数据,请使用字节字符串(b'\xff\x0a\x82'),然后使用一种PyBytes将其转换为achar*和size的方法:
%typemap(in) (char* data,int size) (Py_ssize_t len) %{
if(PyBytes_AsStringAndSize($input,&$1,&len) == -1)
return NULL;
$2 = (int)len;
%}
请注意,这应该在32位和64位Windows上工作,并且可以将空字节包含在数据中,因为显式提取了大小,并且可以处理64位的可能性Py_ssize_t。
添加回答
举报
0/150
提交
取消