From: superpollo on
>>> def myfun():
.... return "WOW"
....
>>> myfun()
'WOW'
>>>

now, i would like to "list" the funcion definition, something like this:

>>> myfun.somethinglikethis()
def myfun():
return "WOW"
>>>

is there something like this around?

bye
From: Patrick Maupin on
On May 18, 12:31 pm, superpollo <ute...(a)esempio.net> wrote:
>  >>> def myfun():
> ...     return "WOW"
> ...
>  >>> myfun()
> 'WOW'
>  >>>
>
> now, i would like to "list" the funcion definition, something like this:
>
>  >>> myfun.somethinglikethis()
> def myfun():
>      return "WOW"
>  >>>
>
> is there something like this around?
>
> bye

Sure, just give it a docstring and then you can call help on it:

>>> def myfun():
.... ''' myfun returns "WOW" when called.
.... This is just a Python __doc__ string
.... '''
.... return "WOW"
....
>>> help(myfun)

Regards,
Pat
From: superpollo on
Patrick Maupin ha scritto:
> On May 18, 12:31 pm, superpollo <ute...(a)esempio.net> wrote:
>> >>> def myfun():
>> ... return "WOW"
>> ...
>> >>> myfun()
>> 'WOW'
>> >>>
>>
>> now, i would like to "list" the funcion definition, something like this:
>>
>> >>> myfun.somethinglikethis()
>> def myfun():
>> return "WOW"
>> >>>
>>
>> is there something like this around?
>>
>> bye
>
> Sure, just give it a docstring and then you can call help on it:
>
>>>> def myfun():
> ... ''' myfun returns "WOW" when called.
> ... This is just a Python __doc__ string
> ... '''
> ... return "WOW"
> ...
>>>> help(myfun)
>
> Regards,
> Pat

mmm... thanks but not quite what i meant :-(

bye

From: Patrick Maupin on
On May 18, 1:41 pm, superpollo <ute...(a)esempio.net> wrote:
> Patrick Maupin ha scritto:
>
>
>
> > On May 18, 12:31 pm, superpollo <ute...(a)esempio.net> wrote:
> >>  >>> def myfun():
> >> ...     return "WOW"
> >> ...
> >>  >>> myfun()
> >> 'WOW'
>
> >> now, i would like to "list" the funcion definition, something like this:
>
> >>  >>> myfun.somethinglikethis()
> >> def myfun():
> >>      return "WOW"
>
> >> is there something like this around?
>
> >> bye
>
> > Sure, just give it a docstring and then you can call help on it:
>
> >>>> def myfun():
> > ...     ''' myfun returns "WOW" when called.
> > ...         This is just a Python __doc__ string
> > ...     '''
> > ...     return "WOW"
> > ...
> >>>> help(myfun)
>
> > Regards,
> > Pat
>
> mmm... thanks but not quite what i meant :-(
>
> bye

Well, I don't think Python remembers exactly how you typed it in, but
you can always ask Python for what it remembers about the function:

>>> def myfun():
.... return "WOW"
....
>>> import dis
>>> dis.dis(myfun)
2 0 LOAD_CONST 1 ('WOW')
3 RETURN_VALUE


The inspect module is useful, as well. But AFAIK Python doesn't
"remember" the source code for stuff you typed in. (For functions in
imported modules, there is sufficient information remembered for
tracebacks to allow you to print out the lines of a function.)

Regards,
Pat
From: superpollo on
Patrick Maupin ha scritto:
> On May 18, 1:41 pm, superpollo <ute...(a)esempio.net> wrote:
>> Patrick Maupin ha scritto:
>>
>>
>>
>>> On May 18, 12:31 pm, superpollo <ute...(a)esempio.net> wrote:
>>>> >>> def myfun():
>>>> ... return "WOW"
>>>> ...
>>>> >>> myfun()
>>>> 'WOW'
>>>> now, i would like to "list" the funcion definition, something like this:
>>>> >>> myfun.somethinglikethis()
>>>> def myfun():
>>>> return "WOW"
>>>> is there something like this around?
>>>> bye
>>> Sure, just give it a docstring and then you can call help on it:
>>>>>> def myfun():
>>> ... ''' myfun returns "WOW" when called.
>>> ... This is just a Python __doc__ string
>>> ... '''
>>> ... return "WOW"
>>> ...
>>>>>> help(myfun)
>>> Regards,
>>> Pat
>> mmm... thanks but not quite what i meant :-(
>>
>> bye
>
> Well, I don't think Python remembers exactly how you typed it in

yes python does not, but maybe the *shell* does, or so i thought. i just
wanted to dump the code for the function in a file, after i tested in
the shell...