Newbie: word count and Win32

Bengt Richter bokr at oz.net
Tue Mar 19 17:20:39 EST 2002


On Tue, 19 Mar 2002 20:51:22 GMT, Joe Christl <jScPhArMistl at att.net> wrote:

>On 19 Mar 2002 20:26:34 GMT, bokr at oz.net (Bengt Richter) wrote:
>
>>
>>From a quick look that[1] script, it looks like it expects to read
>>from stdin only. I.e., it says
>>
>>    # iterate over each line on stdin
>>    for line in sys.stdin.readlines() :
>>        ...
>
>I emailed the author of the post (Derrick Hudson) and that was what he told me
>too.  
>
>>
>>To feed the script's stdin you'll have to redirect or pipe data to it.
>>To pipe stuff on windows to a python script you have to run the interpreter
>>(python) explicitly one way or another, so I would try:
>>
>>    python count.py < foo.txt
>>
>>or you could pipe the output of the windows type command, like:
>>
>>    type foo.txt | python count.py
>
>The < redirect didn't seem to work from a Win32 standpoint.  I tried the:
>
>python count.py < foo.txt 
>...and...
>python count.py foo.txt
>
>... with failed results.  I forgot about the pipe |
>
The script worked unchanged for me on NT4 using

    python count.py < foo.txt 

Were you in a console window with foo.txt in your current directory?
(Did you have a foo.txt file with some data? ;-)

If you con't have some data handy, use the file itself:

    python count.py < count.py

Try it again, and post a verbatim copy of your screen where it fails (if it does).
(to copy windows console text, use Alt=Spacebar>E>K or the system menu in the top left
and Edit>Mark. Then select by mousing a box to enclose the text, and press Enter. Then
paste that into your post. Then we can see what the "failed results" were ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list