[IronPython] if __name__ == '__main__' broken in RC2?

Shri Borde Shri.Borde at microsoft.com
Wed Aug 30 20:33:49 CEST 2006


pythonEngine.Execute("print __name__") is exactly the same as doing pythonEngine.Execute("print __name__", pythonEngine.DefaultModule). The issue is that the name of pythonEngine.DefaultModule is not "__main__". Also, it is not published in sys.modules since its upto the host to determine which modules are published and which are not.

So you would need to do the following for it to print "__main__".

bool shouldPublishMainModule; // You get to chose what this value should be. It should probably be true for "__main__".
EngineModule mainModule = pythonEngine.CreateModule("__main__", shouldPublishMainModule);
pythonEngine.Execute("print __name__", mainModule)

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Wednesday, August 30, 2006 8:49 AM
To: Discussion of IronPython
Subject: Re: [IronPython] if __name__ == '__main__' broken in RC2?

We haven't had any other reports of issues like this so we'll need some more details.

Are you creating a module named __main__ ?  (the console creates an engine named __main__, but if you're using the engine directly we never create a __main__ module for you).  How is it not evaluating properly?  Are we thinking we're in main or not in main?


From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Jesse Wiles
Sent: Wednesday, August 30, 2006 7:51 AM
To: Discussion of IronPython
Subject: [IronPython] if __name__ == '__main__' broken in RC2?

Hi,

I'm running into a problem where if __name__ == '__main__' is not evaluating properly when using PythonEngine from my assembly.  Is this a known issue?

Thanks,
Jesse Wiles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060830/979303eb/attachment.html>


More information about the Ironpython-users mailing list