By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,771 Members | 1,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,771 IT Pros & Developers. It's quick & easy.

import __main__ where can i find a module called "__main__.py"?

P: n/a
wen
and, in which case, the following case will happen:
if __name__!='__main__':
do_sth()

any help would be appreciated.
Aug 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wen wrote:
and, in which case, the following case will happen:
if __name__!='__main__':
do_sth()

any help would be appreciated.

Sorry, but your question is rather difficult to interpret.

For a start, you don't need/want to import __main__.

On import, __name__ is set to the name of the module. When a source file
is run as a script, there is no module, so __name__ is set to the dummy
value "__main__". The module __main__ doesn't exist, and its source file
__main__.py doesn't exist either (this side of the looking-glass).

Below is a minimal example of the behaviour of __name__.

C:\junk>type wenmain.py
print "__name__:", __name__

C:\junk>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import wenmain __name__: wenmain ^Z


C:\junk>python wenmain.py
__name__: __main__

Hope this helps,
John
Aug 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.