how to switch from os.tmpnam to os.tmpfile
Maric Michaud
maric at aristote.info
Thu Jun 8 11:13:49 EDT 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(
"gnuplot", shell=True,
stdin=subprocess.PIPE, stdout=tmp
)
stdout,stderr = gnuplot.communicate("""
set terminal tkcanvas interact
set output /dev/stdout
""" % tmp + commands)
should do the job.
> assert not stderr
> self.tk.call("source",tmp)
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.
--
_____________
Maric Michaud
_____________
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
More information about the Python-list
mailing list