[IPython-dev] test from where a module is imported

Matthias Bussonnier bussonniermatthias at gmail.com
Fri Jul 18 06:25:57 EDT 2014


Le 16 juil. 2014 à 16:19, Johann Rohwer a écrit :

> Hi all,
> 
> Say I'm developing a Python module and would like to know from where the user 
> imports this module, i.e.

> from a regular Python shell, an IPython shell,

in main namesapace, that's easy check fro __IPYTHON__
or even get_ipython() to get a handle in current runnig process. 


> an 
> IPython qtconsole, or an IPython notebook.

You cannot distinguish, and it does not make sense to try to distinguish theses.
Hence we do not plan to add capability do distinguish. (Plenty of description on why
on the ML archive) 

>  I would like to enable additional 
> features in my module depending on e.g. useful stuff that is available in the 
> notebook. But I want the module also to be able to be imported and run in any 
> of the other environments, so it's really more like a test from where we are 
> imported.


What are you exactly trying to do ? 

> 
> I can think of various hacks on how to achieve this but would like to know if 
> there is The Right Way (TM) and if so, what it is.

isn't the _repr_*_ enough ? 
-- 
Matthias

> 
> Thanks,
> Johann
> 
> 
> The integrity and confidentiality of this email is governed by these terms / Hierdie terme bepaal die integriteit en vertroulikheid van hierdie epos. http://www.sun.ac.za/emaildisclaimer
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev




More information about the IPython-dev mailing list