@mainfunction
def main():
print "Hello, World."
if __name__ == '__main__':
print "Hello, World."
Yes. Having functionality and some test of that functionality in the same module simplifies file organisation/maintenance. The test typically also provides extra documentation of the functionality ("this is how you use it").
On 22/11/2013 22:27, Eric Snow wrote:
On Fri, Nov 22, 2013 at 3:02 PM, David Mertz <mertz@gnosis.cx> wrote:
I'm not in love with the *spelling* of " if __name__=='__main__': ", but IYou're right and I think it's a good pattern too. That is something
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.
we do in the stdlib (and increasingly so). It slipped my mind. I've
also seen the idiom used for initiating tests (not that I necessarily
condone that practice), though less so in large projects. It would be
nice if we could address the issues outlined in PEP 395.
Rob Cliffe
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas