我正在尝试使用tempfile模块。(http://docs.python.org/2.7/library/tempfile.html)
我正在寻找一个临时文件,我可以打开几次,以获得几个流来读取它。tmp = ...
stream1 = # get a stream for the temp file
stream2 = # get another stream for the temp file
我尝试了几个函数(TemporaryFile、NamedTemporaryFile、SpooledTemporaryFile)并使用了fileno方法,但我无法执行所需的操作。
你知道我应该自己上课吗?
谢谢
>;更新
试图打开名为的文件时出错。。。In [2]: t = tempfile.NamedTemporaryFile()
In [3]: t.write('abcdef'*1000000)
In [4]: t.name
Out[4]: 'c:\users\mike\appdata\local\temp\tmpczggbt'
In [5]: f = open(t.name)
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
in ()
----> 1 f = open(t.name)
IOError: [Errno 13] Permission denied: 'c:\users\mike\appdata\local\temp\tmpczggbt'