This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author leonov
Recipients leonov
Date 2009-07-22.01:54:21
SpamBayes Score 2.4088578e-09
Marked as misclassified No
Message-id <1248227663.52.0.385641131196.issue6541@psf.upfronthosting.co.za>
In-reply-to
Content
According the docs for the tempfile module, SpooledTemporaryFile()
should operate "exactly as TemporaryFile() does".  However, while
playing around trying to learn the module I found a couple of places
where this is not the case: 

import tempfile

hello = bytes('Hello World!', encoding='utf-8')
tf = tempfile.TemporaryFile()
stf = tempfile.SpooledTemporaryFile()

tf.write(hello)
stf.write(hello)

# (1) Read after write behaviour differs...
>>> print(tf.read())  
b'Hello World'
>>> print(stf.read())
b''

# ...unless you seek first
>>> tf.seek(0)
>>> stf.seek(0)
>>> print(tf.read())
b'Hello World'
>>> print(stf.read())
b'Hello World'


# (2) Name attribute is fragile...
>>> print(tf.name)
3
print(stf.name)
AttributeError: '_io.BytesIO' object has no attribute 'name'

# ...until StringIO object replaced
stf.rollover()
print(stf.name)   # 4

I'm not sure if this should be categorised as a documentation or code
issue. In either case please be gentle -- I'm still just learning Python
(evaluating it as a [now likely] replacement for PHP for web application
development in our company).  I'm filing this bug because, as a
beginner, I was confused by the inconsistency between the docs and the
actual behaviour.

I'd be happy to try and write documentation and/or unit tests about
this, if somebody would be willing to review them for me... :-)
History
Date User Action Args
2009-07-22 01:54:23leonovsetrecipients: + leonov
2009-07-22 01:54:23leonovsetmessageid: <1248227663.52.0.385641131196.issue6541@psf.upfronthosting.co.za>
2009-07-22 01:54:22leonovlinkissue6541 messages
2009-07-22 01:54:21leonovcreate