Nov. 22, 2013
4:19 p.m.
On Fri, 22 Nov 2013 14:02:27 -0800 David Mertz <mertz@gnosis.cx> wrote:
I'm not in love with the *spelling* of " if __name__=='__main__': ", but I very frequently use the overall pattern.
Much--or even most--of the time when I write a module, I like to allow it to either do a minimal case of its basic functionality and/or have the module run some basic unit tests as a quick check against breakage. So in contrast to Eric Snow, I try *to* make my files both scripts and modules. I know this isn't the only possible approach, but I don't think it's bad or uncommon.
I agree with this, and we actually use it quite a bit in the stdlib (try e.g. "python -m zipfile -h"). Regards Antoine.