ipython question

Robert Kern robert.kern at gmail.com
Wed May 19 16:24:13 EDT 2010


On 5/19/10 3:10 PM, superpollo wrote:
> Robert Kern ha scritto:
>> On 5/19/10 12:11 PM, superpollo wrote:
>>> In [39]: def f():
>>> ....: return 42
>>> ....:
>>>
>>> In [40]: %psource f
>>> No source found for f
>>>
>>> In [41]:
>>>
>>> i expected to see the source...
>>
>> You will want to ask IPython questions on the IPython mailing list:
>>
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>>
>> The reason you do not get the source is because there is no file that
>> contains functions defined in the interactive interpreter. %psource
>> uses the inspect module, and the inspect module explicitly only looks
>> in real files
>
> but still:
>
> In [218]: def f():
> .....: return 42
> .....:
>
> In [219]: %save tmp.py 218
> File `tmp.py` exists. Overwrite (y/[N])? y
> The following commands were written to file `tmp.py`:
> def f():
> return 42
>
>
> In [220]: !cat tmp.py
> def f():
> return 42
>
> In [221]: %psource f
> No source found for f

So? The function object f knows nothing about the file tmp.py. If you were to 
import tmp and then ask for %psource tmp.f, it should work.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list