Help with python output redirection

John Machin sjmachin at lexicon.net
Sat Apr 15 18:32:08 EDT 2006


On 16/04/2006 12:36 AM, fatal.serpent top-posted:
> Thank you. Also this script is PublicDomain right?

Wrong. If you attempt to turn "The D'Aprano Code" into a best-seller, 
and don't donate assign all of your royalties to the PSF, they will 
pursue you and your descendants to the ends of the universe.

> Steven D'Aprano wrote:
>> On Fri, 14 Apr 2006 16:59:13 -0700, fatalserpent wrote:
>>
[snip]
>> From the shell, you are probably doing something like this:
>>
>> $ python mymodule.py
>>
>> Change it to this:
>>
>> $ python mymodule.py > 2
>> $ python 2 > 3
>> $ python 3 > 4
>>
>> and so on.
>>
>> Alternatively, you can do this:
>>
>> x = ['f = file("2", "w")', 'print >>f, "x =", x',
>>      'for m in x: >>f, print m']
>> print >>f, "x =", x
>> for m in x: print >>f, m
>>
>> I'll leave changing the file name from "2" to "3" etc. as an exercise for
>> you.
>>
>>
>> -- 
>> Steven.
> 



More information about the Python-list mailing list