how to switch from os.tmpnam to os.tmpfile
maric at aristote.info
Thu Jun 8 17:13:49 CEST 2006
Well, I never used gnuplot and I didn't use Tkinter for a while, but :
Le Jeudi 08 Juin 2006 16:44, Harold Fellermann a écrit :
> tmp = os.tmpnam()
> gnuplot = subprocess.Popen(
> "gnuplot", shell=True,
> stdin=subprocess.PIPE, stdout=file(tmp,"w")
> stdout,stderr = gnuplot.communicate("""
> set terminal tkcanvas interact
> set output "%s"
> """ % tmp + commands)
assuming tmp is a os.tmpfile and you connect it to the the stdout of your
gnuplot command, something like :
gnuplot = subprocess.Popen(
stdout,stderr = gnuplot.communicate("""
set terminal tkcanvas interact
set output /dev/stdout
""" % tmp + commands)
should do the job.
> assert not stderr
You still need to find a way to pass directly a file object to this call.
Also note if that works, and if you don't need to flush the datas on disk (if
they fit in memory), you can use a file-like buffer (StringIO) instead of a
tmpfile, this will save resources.
This said, you should consider writing your temporary file in a directory
owned by you and not world writeable, which is perfectly safe.
Aristote - www.aristote.info
3 place des tapis
Tel: +33 426 880 097
More information about the Python-list