From: Peter Otten on 18 May 2010 15:08 superpollo wrote: > 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... You could try ipython: $ ipython Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: def f(): ...: return 42 ...: In [2]: f() Out[2]: 42 In [3]: %save tmp.py 1 The following commands were written to file `tmp.py`: def f(): return 42 In [4]: Do you really want to exit ([y]/n)? $ cat tmp.py def f(): return 42 $ Peter
From: superpollo on 18 May 2010 15:13 Peter Otten ha scritto: > superpollo wrote: > >> 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... > > You could try ipython: > > $ ipython > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > Type "copyright", "credits" or "license" for more information. > > IPython 0.10 -- An enhanced Interactive Python. > ? -> Introduction and overview of IPython's features. > %quickref -> Quick reference. > help -> Python's own help system. > object? -> Details about 'object'. ?object also works, ?? prints more. > > In [1]: def f(): > ...: return 42 > ...: > > In [2]: f() > Out[2]: 42 > > In [3]: %save tmp.py 1 > The following commands were written to file `tmp.py`: > def f(): > return 42 > > > In [4]: > Do you really want to exit ([y]/n)? > $ cat tmp.py > def f(): > return 42 > $ > > Peter <RUNS TO APT-GET> hey great! thanks a lot! best regards
From: Ethan Furman on 18 May 2010 15:26 superpollo wrote: > 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... Take a look at ipython -- it has many enhancements: ipython.scipy.org ~Ethan~
From: René 'Necoro' Neumann on 18 May 2010 15:21 Am 18.05.2010 20:55, schrieb superpollo: > > 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... You might want to have a look at the IPython shell [1]. I personally do not use it myself, but I thought to remember that it had some feature like this (perhaps not dump _one function_, but all the input, which you then only need to cleanup). A quick glance revealed f.ex. the history and edit functionality [2] -- a bit more digging might really show up the thing you are looking for. - René [1] http://ipython.scipy.org/ [2] http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html#source-code-handling-tips
From: Terry Reedy on 18 May 2010 22:36 On 5/18/2010 2:55 PM, superpollo wrote: > 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... On Windows, you can tell the shell (command window) how many lines to remember. One can sensibly make this a lot higher on a gigabyte machine than back in the 640K days. No idea about other systems.
First
|
Prev
|
Pages: 1 2 Prev: Is there conversion method to convert pyunicodeobject topybyteobject? Next: upgrade python |