[Tutor] creating objects in a loop
Alexandre Ratti
alex@gabuzomeu.net
Wed, 03 Apr 2002 10:09:46 +0200
Hi Erik,
At 22:45 02/04/2002 -0500, Erik Price wrote:
>>if __name__ == "__main__":
>> cat = factory(Pets, "fluffy")
>> print cat
>
>The "if __name__ == '__main__':" test -- I have seen it several times
>now. Why is this test performed? Isn't it obvious that __name__ is
>__main__ ? Or am I missing something....
__name__ only has the value "__main__" when the code is run as a standalone
module. This is handy for testing: you can add test code in this section
and it only runs when you launch execution from *this* module. If you just
import your classes or functions into another module, the test code does
not run.
>Erik
>
>PS: I truly am sorry that I have so many questions,
Don't be and ask away; this is what this list is meant for :-)
>but the more I learn the more I realize I don't know a lot of things.
Same here.
Cheers.
Alexandre