I can not comment on the answers, so I will post my comment here:
To create a temporary file for write access, you can use tempfile.mkstemp and specify "w" as the last parameter, for example:
f = tempfile.mkstemp("", "", "", "w")
MartinD Jun 05 '13 at 14:15 2013-06-05 14:15
source share