On 18 Jan 2008, 06:42:26, Steve Holden wrote: > Ole.Nielsen at ga.gov.au wrote: > > Thank you very much for the quick reply. > > > > I believe we have to close the file in order be able to read it in - in this > > case to feed a unittest. I actually tried to read it in before closing it, > > but (as I suspected) the data wasn't available. > The mistake you made was to change the mode from the default "w+b". The > following code works on both Windows and Linux: > > from tempfile import NamedTemporaryFile > fid = NamedTemporaryFile(mode='w+b', > suffix='.tmp', > dir='.') > > fid.write('My temp file') > fid.seek(0) > data = fid.read() > print data > fid.close() If you need to read the data by opening the file again (from unittest code for example), then you need to call fid.flush() (no need for seeking). Again, comp.lang.python, but I could not resist. regards.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4