Python by Swaroop C H - HTML preview
PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.
Download the book in PDF, ePub, Kindle for a complete version.
Using a module's __name__
Example 8.2. Using a module's __name__
#!/usr/bin/python# Filename: using_name.py if __name__ == '__main__':
else: print 'This program is being run by itself' print 'I am being imported from another module'
Output
$ python using_name.pyThis program is being run by itself
$ python
>>> import using_name
I am being imported from another module >>>
