Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Dec 182010

How do I find the current module name in Python?


The easiest way is to look at the look at the predefined global variable __main__. If it has the value "__main__", it means the program is run as a script (not as imported module).


def main():
    print 'Running test...'

if __name__ == '__main__':

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>