【发布时间】:2013-08-20 00:33:09
【问题描述】:
我有一个函数需要一个文件对象,简化示例:
def process(fd):
print fd.read()
通常被称为:
fd = open('myfile', mode='r')
process(fd)
我无法更改此功能,并且我已经在内存中拥有文件的内容。有没有办法convert 将文件内容写入文件对象而不将其写入磁盘,所以我可以这样做:
contents = 'The quick brown file'
fd = convert(contents) # ??
process(fd)
【问题讨论】:
标签: python string file file-io