[IPython-dev] IPython-dev Digest, Vol 133, Issue 1

Jean Bigboute jeanbigboute at gmail.com
Mon Feb 2 12:25:10 EST 2015


[ deletia ]

Thomas's solution worked on both Anaconda and Enthought Canopy for
Windows.  A fresh installation of Anaconda fixed the kernmagic problem
on the Mac.  A couple of minor tweaks were needed to the code itself
to get it to go on all three.  I think I didn't understand the error
messages generated when the code loaded.

import inspect
def source(func):
     print inspect.getsource(func)

does the job via the startup file.

Thanks for the advice.

JBB

> Message: 4
> Date: Sat, 31 Jan 2015 19:41:41 -0800
> From: Jean Bigboute <jeanbigboute at gmail.com>
> Subject: Re: [IPython-dev] Two basic Notebook questions (Python focus)
> To: ipython-dev at scipy.org
> Message-ID:
>         <CAEen6uyY6u=z95stNyJ5qxk=h=T62NWJoqdrA5S2_5RoJmCb1w at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> On Sat, Jan 31, 2015 at 10:00 AM,  <ipython-dev-request at scipy.org> wrote:
>
>>
>> Message: 4
>> Date: Fri, 30 Jan 2015 15:48:59 -0800
>> From: Thomas Kluyver <takowl at gmail.com>
>> Subject: Re: [IPython-dev] Two basic Notebook questions (Python focus)
>
>> On 30 January 2015 at 15:26, Jean Bigboute <jeanbigboute at gmail.com> wrote:
>>
>>> b) Is it possible to pass arguments to a magic function?
>>> e.g.
>>> import inspect
>>> print inspect.getsource(function)
>>>
>>
>> This is probably easiest to do in a plain Python function. Create a file
>> ~/.ipython/profile_default/startup/printsource.py (which IPython will
>> automatically run when it starts, and put in it:
>>
>> import inspect
>> def source(func)
>>     print inspect.getsource(function)
>>
>> Now you can just type 'source(f)' to see a function in your notebook. Be
>> aware, though, that if you share that notebook, other people won't have the
>> source() function defined. You could also define it at the top of the
>> notebook if you prefer.
>>
>> Thomas
>>
>



More information about the IPython-dev mailing list