[PyAR2] Writing to a text file

Coltrey Mather pyar2 at cowsgomoo.org
Wed Jun 9 15:14:39 CEST 2010


redirecting stdout and piplines also works on windows/dos

c:\python25\python.exe script.py > results.txt
c:\python25\python.exe script.py | more

Since this is supposed to by a Pythonic place...you can do file i/o in your
script
http://docs.python.org/library/stdtypes.html#file-objects

basically,
f = open('results.txt', 'w') # note that this will overwrite any data in
results.txt
f.write('a line full of stuff\n')
f.close()



On Tue, Jun 8, 2010 at 23:41, Derek Horton <derek.k.horton at gmail.com> wrote:

> Since you are using linux there are a couple of things you can do.  First,
> you could redirect the output (stdout) of your script to a file and then use
> an editor to view the file.
>    python script.py > results.txt
> Now open the results.txt file in your favorite editor.
>
> Or you could pipe the output into less which will allow you to page through
> the output of your script by hitting the space bar.
>    python script.py | less
>
> HTH
>
> Later,
> Derek
>
> On Tue, Jun 8, 2010 at 10:09 PM, Daniel Veazey <daniel at danielveazey.com>wrote:
>
>>  Hi, I'm totally new. I wrote a short program to find combinations on a
>> bike lock that have adjacent double digits. The lock has 4 digits, and each
>> digit can have a value of 1-6. So 1442 would have adjacent double digits,
>> and 1424 would not. Here is the program:
>>
>> http://pastebin.com/SzGCwMR9
>>
>> The problem I'm having is that when I run the program in a Linux terminal,
>> by the time all the combinations have been printed, the first half of the
>> combinations have run out of the top of the terminal's window.
>>
>> So what I'd like to do is instead of just printing the numbers on the
>> screen, write them to a text file. Is there a way to do this? Does it have
>> something to do with stdout?
>>
>> Thanks,
>>
>> Daniel Veazey
>> danielveazey.com <http://www.danielveazey.com>
>>
>> _______________________________________________
>> PyAR2 mailing list
>> PyAR2 at python.org
>> http://mail.python.org/mailman/listinfo/pyar2
>>
>>
>
> _______________________________________________
> PyAR2 mailing list
> PyAR2 at python.org
> http://mail.python.org/mailman/listinfo/pyar2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/pyar2/attachments/20100609/ed036c07/attachment.html>


More information about the PyAR2 mailing list