[Tutor] NEWBIE!! pipes

David Porter jcm@bigskytel.com
Thu, 1 Feb 2001 17:29:55 -0700

* AquaRock7@aol.com <AquaRock7@aol.com>:

> 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?


I haven't done anything with pipes yet.

> 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 ?

Each module has a __name__ attribute. The directly executed file (not
imported) has the __name__ of "__main__". Even an interpretter session has
the name of "__main__":

>>> __name__
>>> import os
>>> os.__name__

Basically, the purpose of the above code is to make python do different
things when the file is run as a script and when it is imported as a
module. If it is being run as a script, execute main().

As for the question about __X__ type names, I think it is merely like that
for __name__ to distinquish it from your variables with the added bonus of
not stealing a valuable keyword from us, name. __X__ type names are more
significant when you deal with classes, where they are hooks used for
operator overloading.