如何使用 Python 中的内存映射文件并将其传递给需要文件名的外部 API?
我必须从 Python 2.5 调用一个外部 API (win32),它要求我提供文件名并返回结果。
为了加速该过程,我不想将数据保存到经典文件中,我更愿意将其保存在内存中并在 API 调用返回后释放它。
外部函数只需要读取访问权限。
我查看了 mmap
但示例不是很广泛; )
I have to call, from Python 2.5, an external API (win32) that request me to provide a filename and return a result.
In order to speedup the process I don't want to save the data into a classic file and I would prefer to save it in memory and release it after the API call returns.
The external function does need only read access.
I looked at mmap
but the examples were not quite extensive ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过使用命名管道吗?
在 Windows 上,可以使用标准文件函数(
CreateFile()
、ReadFile()
、WriteFile()
...)访问命名管道,使用\\.\pipe\name
形式的特殊文件名。您的外部 API 可能能够从管道中读取数据,该管道是您从 python 脚本创建的管道,并提供必要的数据。have you tried using a named pipe ?
on Windows, a named pipe can be accessed using standard file functions (
CreateFile()
,ReadFile()
,WriteFile()
...), using a special filename of the form\\.\pipe\name
. your external API may be able to read from the pipe, a pipe that you would create from your python script and feed with the necessary data.