Hi, why not use tempfile standard package with specifying a prefix, so that you both have insurance that the file is not existing and unpredictable, andi correct lexicographic order :
import tempfile for i in range(10): file_path = tempfile.mkstemp(prefix='tmp{}'.format(i), dir='/tmp')[1] with open(file_path, 'w') as f: f.write('hop') Ciao, Thierry On Tue, Jul 01, 2014 at 10:06:18AM -0700, Niles Johnson wrote: > > > > On Tuesday, July 1, 2014 12:45:57 PM UTC-4, Nils Bruin wrote: > > > > > > It probably was intended. As a general rule, temporary files live in > > directories where multiple entities have file creation privileges, > > including ones that don't necessarily trust each other fully. If you're > > creating filenames via a predictable pattern, you're vulnerable to a denial > > of service, since an adversary might try and predict which file you're > > going to try and create next and do that before you. > > > > This is my understanding too > > > > What you're describing is a situation where the files weren't intended to > > be temporary after all--apparently they're output. The proper solution is > > of course to save your plots instead: > > > > > If you want to save and view this output in a temporary directory, you can > get one with tmp_dir [1]. And, if you want the old functionality, you can > use graphics_filename [2]. Note that the latter isn't automatically > imported to the global namespace, so you need to do it manually. A simple > way would be > > from sage.misc.temporary_file import graphics_filename as gf > > And then use it like this: > > for i in range(10): > plot(sin(i*x),-1,1).save(gf()) > > > > [1] > http://www.sagemath.org/doc/reference/misc/sage/misc/temporary_file.html#sage.misc.temporary_file.tmp_dir > > [2] > http://www.sagemath.org/doc/reference/misc/sage/misc/temporary_file.html#sage.misc.temporary_file.graphics_filename > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.