[Tutor] NEWBIE!! pipes

Bruce Sass bsass@freenet.edmonton.ab.ca
Thu, 1 Feb 2001 11:22:49 -0700 (MST)

On Wed, 31 Jan 2001 AquaRock7@aol.com wrote:
> What are pipes?  The docs barely touched this subject, it assumed you already 
> knew what they are...  From context I am gathering that it is a connection to 
> the kernel?  (maybe?)  How can I utilize this?

A "pipe" is a connection between two programs, from the stdout of one to
the stdin of another.  On a unix command line you would write it as:
	prog1 | prog2 | prog3

Which would pipe the output of prog1 to the input prog2, etc.

> 1 more quickie:
> >if __name__ == '__main__':
> >     main()
> what is the pourpose if the above code?  It runs the sub main() (duh :) but, 
> why not just main() wihtout the if?  what is the conditional testing for?  
> and what are the variables __main__ and __name__?  i dont believe they are 
> defined in the program, so just what are they?  and, what does putting "__" 
> around a variable actually DO besides look cool ?

Ya, cool, until you try to read it done in a proportional font and can't
tell how many underscores are present.  anyways...

When Python is executing the mainline of a program __name__ has the
value "__main__", so, the above snippet would only execute the main()
routine if the code was being executed as part of the mainline of a
program.  i.e., doing "python snippet" would execute main(), doing
"import snippet" from within a Python program would not.  It tends to
be used it like this...

----- module: snip2
class C1:

class C2:

def f1:

def main():
    # class and function test routine

if __name__ == "__main__":

When I want to test what I'm woring on I do "^C^C" to execute the
buffer, __name__ == "__main__" and the test code is run; when a prg
imports the finished module the test code is ignored.  The prog doing
the importing could also do a "snip2.main()" to run the test code.