[IPython-user] __main__ vs __main__
Thu Jan 3 16:11:33 CST 2008
Is there a nice way of getting ipython to use the original __main__
rather than creating its own? In my code, I have python calling C code,
which then calls python code, using PyRun_SimpleString. The
PyRun_SimpleString will call, for example, a function defined in python
before the C code is called. This works fine in plain python. But not in
ipython - it by default creates its own name space which
PyRun_SimpleString can't directly get at. I came up with the following,
which seems to work ok,
__main__.__name__ = "__mynamespace__"
Setting __name__ is needed to prevent the ipython __main__ from being
replaced by a FakeModule, which doesn't seem to interact with
PyRun_SimpleString. Is this a sensible solution? Has anyone else done
this kind of thing?
Any and all comments welcome! Thanks!
More information about the IPython-user