I have gone through various post and explanations for the above keywords [__name__
and __main__
].
Please confirm if my understanding is Correct
1.__name__
saves the name of the file automatically when a file is edited & saved.
2.__main__
is updated through command prompt.
What is the value stored in __main__
when its not initialized ?
Can I program the __main__
to access the conditional code in the file?
For example, I have two files a.py
and b.py
a.py
import b
# Can I program here '__main__' to access the functionality in b?
# So that I can print the condition is true if __name__ == '__main__':
b.py
if __name__ == '__main__':
print 'This program is being run by itself'
else:
print 'I am being imported from another module'
Please comment your views on understanding and Possibility of access/modifying __main__