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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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

_______________________________________________
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to