[Tutor] Questions about stdin, stdout, lists and tuples

Sheila King sheila@thinkspot.net
Mon, 08 Jan 2001 13:40:16 -0800

On Mon, 8 Jan 2001 11:29:25 -0500, D-Man <dsh8290@rit.edu>  wrote about Re:
[Tutor] Questions about stdin, stdout, lists and tuples:

:On Mon, Jan 08, 2001 at 01:04:14PM -0800, Sheila King wrote:
:| Python newbie, here. I come from a C++/Pascal/VB type of background.
:| My first goal is to write some mail filtering scripts in Python to manage my
:| e-mail spam. My e-mail scripts will be fed the incoming e-mail on stdin and I
:| have to write my e-mails to stdout if I want them to be delivered through my
:| MTA.
:It would probably be easier to use procmail for this.  (Although the
:syntax for the "recipes" is confusing -- I only use it to put list
:mail in the right folder)  You can probably find some non-warranted
:recipes on the web somewhere.

Yes, I can't really figure out how to use procmail on my webhost, and believe
me, I've tried. My web host is fantastic, but uses a proprietary mail system,
and no one has yet figured out how to use procmail, although it is installed.

:| I have a couple of questions I want to ask, just to make sure I'm
:| understanding things clearly:
:| Here is a short practice script I just wrote:
:| -----------------------------------------
:| import sys
:| line = sys.stdin.readline()
:| print line
:| -----------------------------------------
:| It reads a single line from stdin and prints it to stdout.
:| My understanding, is that this is equivalent to the C++ program:
:| ----------------------------------------
:| #include <iostream.h>
:| #include <string.h>
:| int main()
:| {
:|    string line;
:|    getline(cin,line);
:|    cout << line;
:|    return 0;
:| }
:| ----------------------------------------
:I'm not familiar with the getline() fuction in C++ (I don't recall
:seeing it in my C++ book, but it would have been useful many times).
:If I can assume that it will read all characters on cin until it finds
:a newline and inserts it into the string 'line', then that is the

Yes, this is what it does. You need to include string.h for this ability. And
it strips the newline character when it does this.

:To duplicate print, you need to add " << endl " to your 'cout' line.

Ah, thanks. The details like this can really much one up later.

:| If anyone would like to confirm/deny/comment on my conclusions about
:| stdin/stdout, I would be interested. Am I overlooking any Python peculiarities
:| (such as the difference between "input" and "raw_input" or something along
:| those lines.)?
:Input is (nearly?) equivalent to eval( raw_input() ).  It will
:evaluate the input and return the appropriate object (ie, int, list,
:string, etc).
:Raw_input doesn't evaluate the input, but returns the raw string for
:you to deal with.

Thanks. Good info.

...<comments about arrays, lists, etc... deleted>...

Sheila King