<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Paul:
<div><br>
</div>
<div>Works like a charm, many thanks!</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Tim</div>
<div><br>
<div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  ">Timothy
 M. Shead<br>
Sandia National Laboratories<br>
1461, Scalable Analysis and Visualization</span> </div>
<br>
<div>
<div>On May 7, 2014, at 5:25 PM, Paul Ivanov <<a href="mailto:pi@berkeley.edu">pi@berkeley.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">Shead, Timothy, on 2014-05-07 23:01,  wrote:<br>
<blockquote type="cite">I have some code that I’d like to execute only when run from<br>
within ipython … is there any way to know?  I’m already<br>
importing the required ipython modules in a try … catch block,<br>
so my code handles the case where IPython isn’t installed, but<br>
that doesn’t address the case where ipython is installed but<br>
not in use.<br>
</blockquote>
<br>
When running ipython, we expose the function `get_ipython` to get<br>
a handle on the current IPython instance. So in an interactive<br>
setting, you could just check for that and catch a name error.<br>
<br>
More generally, you can do this:<br>
<br>
   from IPython import get_ipython<br>
<br>
Calling get_ipython() will return None if IPython isn't running,<br>
otherwise it will return an IPython shell object.<br>
<br>
best,<br>
-- <br>
                  _<br>
                 / \<br>
               A*   \^   -<br>
            ,./   _.`\\ / \<br>
           / ,--.S    \/   \<br>
          /  `"~,_     \    \<br>
    __o           ?<br>
  _ \<,_         /:\<br>
--(_)/-(_)----.../ | \<br>
--------------.......J<br>
Paul Ivanov<br>
<a href="http://pirsquared.org">http://pirsquared.org</a><br>
_______________________________________________<br>
IPython-dev mailing list<br>
IPython-dev@scipy.org<br>
http://mail.scipy.org/mailman/listinfo/ipython-dev<br>
</blockquote>
</div>
<br>
</div>
</body>
</html>