james91b / ida_ipython

An IDA Pro Plugin for embedding an IPython Kernel
MIT License
252 stars 46 forks source link

Use local namespace #27

Open tmr232 opened 8 years ago

tmr232 commented 8 years ago

Currently, the IPython console and the regular Python console inside IDA have different namespaces.

Is it possible to merge those namespaces?

james91b commented 8 years ago

Should be possible, just change

https://github.com/james91b/ida_ipython/blob/master/python/ipythonEmbed.py#L64-L65

to

        app.kernel.user_module = __main__
        app.kernel.user_ns = __main__.__dict__

When i first did this, older versions in iPython i used to have strange issues with the auto completion and the completer frame. However, after my simple tests, it seems to work fine in Jupyter. So this is a change we could make.

tmr232 commented 8 years ago

Yes, it works :smile:

Now I wonder if that indeed a good idea - as the global namespace is extremely messy.

james91b commented 8 years ago

Yeah, I'm not actually sure what would be more useful. Global namespace can make some thing easier, however it can be messy and if you ever want to affect the global namespace from a notebook you should be able to just import main and do it that way.

We could also make it an option to launch the notebook in a new namespace or the global namespace.

tmr232 commented 8 years ago

The main (and only) use I see for keeping the global namespace is interaction with plugins. I think it is a worthwhile cause. If we have a way to get the all the data from that scope without dirtying the new one, that would be great.