[sugar] Bitfrost compliance for Update.1

Ivan Krstić krstic
Fri Nov 2 14:57:31 EDT 2007


On Nov 2, 2007, at 12:24 PM, Carlos Neves wrote:
> Will os.tempnam() use this dir by default?

No, but it's bad security practice to use os.tempnam unless you  
really know what you're doing (at that point, you can pass in the  
target directory as the 'dir' keyword argument).

Here's how to properly get a temporary file in Python until we  
provide helpers for it through Sugar:

----

import os.path
import tempfile
from os import environ

tmp_root = os.path.join(environ['SUGAR_ACTIVITY_ROOT'], 'tmp')
tmp = tempfile.TemporaryFile(dir=tmp_root)

---

At this point, 'tmp' is a file-like object that you can use normally.

--
Ivan Krsti? <krstic at solarsail.hcs.harvard.edu> | http://radian.org



More information about the Sugar-devel mailing list