如何使 cStringIO 对另一个需要真实本地文件的函数透明
我遇到了以下问题: 代码 A 现在可以工作。我在本地保存一个名为 Chart.png 的 png 文件,然后将其加载到专有函数中(我无权访问该函数)。
但是,在代码 B 中,我尝试使用 cStringIO.StringIO(),这样我就不必将文件“chart.png”写入磁盘。但我找不到将其传递给 pproprietaryfunction 的方法,因为它需要一个像“chart.png”这样的真实文件名(看起来它甚至使用 split 函数来识别扩展名)。
代码 A(正在运行的代码):
file = "chart.png"
pylab.savefig(file, format='png')
a = proprietaryfunction.add(file)
代码 B(我正在尝试执行的操作 - 但不起作用):
file = cStringIO.StringIO()
pylab.savefig(file, format='png')
a = proprietaryfunction.add(file)
如何使 cStringIO.StringIO() 的使用对专有函数透明?无论如何,我可以为此在内存中模拟虚拟文件系统吗?
I came up with the following problem: CODE A works right now.. I am saving a png file called chart.png locally, and then I am loading it into the proprietary function (which I do not have access).
However, in CODE B, am trying to use cStringIO.StringIO() so that I do not have to write the file "chart.png" to the disk. But I cannot find a way to pass it to the pproprietaryfunction because it is expecting a real filename like "chart.png" (it looks like it even uses the split function to identify the extension).
CODE A (code running right now):
file = "chart.png"
pylab.savefig(file, format='png')
a = proprietaryfunction.add(file)
CODE B (what I am trying to do - and does not work):
file = cStringIO.StringIO()
pylab.savefig(file, format='png')
a = proprietaryfunction.add(file)
How can I make the use of cStringIO.StringIO() transparent to the proprietary function? Is there anyway that I can emulate a virtual file system in memory for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论