En Fri, 20 Apr 2007 17:48:10 -0300, CSUIDL PROGRAMMEr <[EMAIL PROTECTED]> escribió:
> On Apr 16, 1:08 pm, Michael Hoffman <[EMAIL PROTECTED]> wrote: >> CSUIDL PROGRAMMEr wrote: >> > hi folks >> > I am new to python. I have a module does call a os.command(cmd) where >> > cmd is a rpm command. >> > Instead of using os.command and getting the results on command line , >> > i would like to dump the output in a file. Is os.command(cmd > >> > filename) the most efficient command?? >> >> I think the best thing to do would be something like this (Python 2.5): >> >> from __future__ import with_statement >> import subprocess >> >> with file("test.out", "w") as outfile: >> subprocess.check_call(["ls", "/etc"], stdout=outfile) >> -- >> Michael Hoffman > > > but what if i have python which is 2.4?? Omit the with statement: import subprocess outfile = open("test.out", "w") try: subprocess.check_call(["ls", "/etc"], stdout=outfile) finally: outfile.close() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list