Execute commands from file

Martin Blume mblume at socha.net
Wed May 16 12:53:31 EDT 2007


"tmp123" schrieb > 
> We have very big files with python commands 
> (more or less, 500000 commands each file).
> 
> It is possible to execute them command by command, 

inp = open(cmd_file)
for line in inp:
    exec line

might help. You don't get quite the same feeling as
"like if the commands was typed one after the other 
in a interactive session", but perhaps this helps.

Warning: the code above is without any error checks.
You might also run into security problems, the example
above assumes you trust your input.

HTH. YMMV.
Martin







More information about the Python-list mailing list