2008年7月13日 星期日

__name__ & __main__

when the file is run as a top-level program,  __name__ is set as __main__

when the file is imported,  __name__ is set to the module's name

Hence, we can use __name__ to do unit test.
If  __name__ == __main__,   we execute unit test
if __name__ != __main__,  unit test is not executed 


沒有留言: