create a tmp file for system execution
Eric Texier
erict at millfilm.co.uk
Wed May 29 13:28:14 EDT 2002
Thanks, building a string with ; was the best for what I needed.
I started to play with os.tmpnam() etc. and it wasn't really
straightforward.
Donn Cave wrote:
> Quoth Eric Texier <erict 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
> ...
> | os.system("csh -c 'source tmpFile' ")
> | os.system("rm -f tmpFile")
>
> You've already gotten some good answers, and you can answer
> your own questions pretty easily just by trying the things
> you propose to do. Here are two more points:
>
> - this takes 4 seconds "wall clock" time on my computer:
> import os
> import string
>
> s = ['ls something somethingelse']*2000
> s.append('exit 17')
> s = string.join(s, '; ')
> t = os.system(s)
>
> (I added the "exit 17" just so I'd have some way to verify that
> it really did everything.)
>
> - If you have a file of commands, you don't need to "source" it,
> you can invoke the shell directly on the file - it's a "script".
>
> - Never use csh if you can avoid it, it's the worst of shells.
> The system() function uses "sh", and that's the right choice for
> most applications.
>
> - I'm assuming a UNIX platform.
>
> Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list