create a tmp file for system execution

Eric Texier erict at millfilm.co.uk
Thu May 30 04:28:35 EDT 2002


Read the second part of the message @@@: IS PYTHON FASTER THAN C ?

The 'ls' command was just an example.
The purpose of the little script was to help the management of big sequence of
file like image.

example:
seq.py 1 1000 2 "convert  image.#.sgi    image.#~4.tiff"

will execute
convert image.i.sgi image.00i.sgi  (from i = 1 to 1000 on 2)
convert being a executable.

@@@
Something interesting about this story.
I wrote the script as a little exercise to mimic a C executable
already use in the company I am working for. I want to convice
them that Python is for many use the way to go.

I found myself with a script 10 time more readable that the C program
    - use of getopt to parse the 4 or 5 option and the argument
    - some rexp to make build the proper command (thanks to Jeff
       Epler for  his help)

The code is half the size.
And most of all, it is faster  (* 2 ) than is C brother. I don't know
how was compile the C code, but the testing was make exactly
in the same environment.
I cannot explain it, beside the fact that the c code poorly written.






Bengt Richter wrote:

> On Wed, 29 May 2002 15:34:57 +0100, Eric Texier <erict at millfilm.co.uk> wrote:
>
> >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")
> >
> >
> >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
> >
> wouldn't it be faster to do a single ls F.* command piped to a grep for
> the decimal extensions, then to a python script for sorting and final formatting
> or whatever you want to do with the file names? Or am I missing something?
>
> Regards,
> Bengt Richter




More information about the Python-list mailing list