Understanding tempfile.TemporaryFile

Shane Geiger sgeiger at ncee.net
Thu Dec 27 22:17:01 EST 2007


import tempfile
tmp = tempfile.mktemp()

import os
os.remove(tmp)



byte8bits at gmail.com wrote:
> Wondering if someone would help me to better understand tempfile. I
> attempt to create a tempfile, write to it, read it, but it is not
> behaving as I expect. Any tips?
>
>   
>>>> x = tempfile.TemporaryFile()
>>>> print x
>>>>         
> <open file '<fdopen>', mode 'w+b' at 0xab364968>
>   
>>>> print x.read()
>>>>         
>
>   
>>>> print len(x.read())
>>>>         
> 0
>   
>>>> x.write("1234")
>>>> print len(x.read())
>>>>         
> 0
>   
>>>> x.flush()
>>>> print len(x.read())
>>>>         
> 0
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy




More information about the Python-list mailing list