[Tutor] Question about stdin/stdout

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun May 30 20:21:11 EDT 2004



On Thu, 27 May 2004, Bob Heasman wrote:

> I have just started programming with Python using the book and disk
> supplied by Michael Dawson, and am rather overawed at the questions and
> answers that I have seen.

Hi Bob,

Don't be overawed.  *grin* If there's stuff that goes over your head, just
skip it.  And if you're finding that there are too many messages coming
from the list, you can turn on "digest mode" on your mailing list settings
from:

    http://mail.python.org/mailman/listinfo/tutor

Near the bottom, there's a form there where you can edit certain options
for your mailing list subscription --- this includes turning on digest
mode, to bundle messages from the list into chunks.


> get Linux to save this display to a file using the "tail -f" command) or
> file, and when it recognises the line with the call sign "UA6ADV" (or
> one of the other call signs) it will then send a cmd to the parallel
> port, ttyS0, to make one of the pins go high.


It will probably be easy to deal with stdin.  Here's a small sample
program that takes stdin, and UPPERCASES every line it can read from the
standard input:

###
import sys
for line in sys.stdin:
    sys.stdout.write(line.upper())
###



> So this uses a file as "stdin", and "stdout" is a pin on the parallel
> port.Can someone give me some pointers as to how to do this, or if
> necessary, point me to a book or a web site where I can find this info.

It sounds that, given some line of text, you'll want to look for a
specific pattern.  If the pattern isn't too complex, you can use a
substring check with the 'in' operator:

###
>>> 'go' in 'chess was invented, but go was discovered'
True
>>> 'othello' in 'chess was invented, but go was discovered'
False
###


If the pattern you're looking for is a little more complex, then the
"regular expression" library may be of more help.  There's a good HOWTO on
regular expressions here:

    http://www.amk.ca/python/howto/regex/


Finally, I'm guessing that you've had some programming experience;  you
might then want to do a quick tour through the standard tutorial at:

    http://python.org/doc/tut

to brush up on Python's feature set.


Good luck to you!




More information about the Tutor mailing list