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

2006-08-30 Thread Jesse Wiles




OK. So, I think I get the how, but
I don't understand the why. If I execute a python file using
PythonEngine.Execute(), why doesn't it just do the right thing? Why do
I have to instruct the embedded engine to behave like the CPython
implementation. Why doesn't it just do it?

Shri Borde wrote:

  
  
  

  
  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
havent had any other reports of issues like this so
well need some more details.
  
  Are
you creating a module named __main__ ? (the console
creates an engine named __main__, but if youre using the engine
directly
we never create a __main__ module for you). How is it not evaluating
properly? Are we thinking were 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
  



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


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

2006-08-30 Thread Shri Borde








The main motivation was to not make policy decisions for the
host. The host may or may not want sys.modules[__main__] to
exist. We leave it up to the host to do whatever is right for its scenario. For
eg, ipy.exe foo.py does not use the default module, and instead creates
a new OptimizedEngineModule and publishes that as __main__.







From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jesse Wiles
Sent: Wednesday, August 30, 2006 4:26 PM
To: Discussion of IronPython
Subject: Re: [IronPython] if __name__ == '__main__' broken in RC2?







OK.
So, I think I get the how, but I don't understand the why. If I execute a
python file using PythonEngine.Execute(), why doesn't it just do the right
thing? Why do I have to instruct the embedded engine to behave like the
CPython implementation. Why doesn't it just do it?

Shri Borde wrote: 

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 havent had any other reports of issues like this so
well need some more details.



Are you creating a module named __main__ ? (the console
creates an engine named __main__, but if youre using the engine directly
we never create a __main__ module for you). How is it not evaluating
properly? Are we thinking were 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 listusers@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com 




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