create a tmp file for system execution

Raymond Hettinger python at rcn.com
Wed May 29 11:24:14 EDT 2002


"Eric Texier" <erict at millfilm.co.uk> wrote in message
news:3CF4E711.8A175798 at millfilm.co.uk...
> I have a py script executing a bunch of os.system in a loop.
> It is not very fast and I was wondering if it will not be better
> to recreate a execution file.
>
> My 2 questions:
>
> 1) what is faster for a big number of call
>
> for i in range(1,2000):
>     os.system("ls  F1.%d   F2.%d" % ( i , i ) "  )
>
> OR
>
> fileOut = open("tmpFile",w)
> for i in range(1,2000):
>     fileOut.write("ls  F1.%d   F2.%d" % ( i , i ) " )
>
> fileOut.close()
> os.system("csh -c 'source tmpFile' ")
> os.system("rm -f tmpFile")

I'm not sure what the overhead is for *nix world, but in the
Windows world, the os.system launches a whole new
command interpreter environment.  It is very costly, so
option two is much faster.

>
>
> 2) if the second one is better I would like to kwo if there is any thing
>
> in python for temporary file, the drag being to if you do not come for
> a specific naming mechanism, you file can be change by and other
> process before it execute

Is os.tmpfile() what you're looking for?


Raymond Hettinger





More information about the Python-list mailing list