[IPython-User] iPython QTConsole - Force yellow quickref guide to appear again?

Aaron Meurer asmeurer@gmail....
Mon Sep 10 09:36:25 CDT 2012


On Mon, Sep 10, 2012 at 2:26 AM, Francesco Montesano
<franz.bergesund@gmail.com> wrote:
> Dear Aaron,
>
> thanks for the detailed description.
>
> 2012/9/10 Aaron Meurer <asmeurer@gmail.com>:
>> On Sat, Sep 8, 2012 at 9:39 PM, Fernando Perez <fperez.net@gmail.com> wrote:
>>> On Thu, Sep 6, 2012 at 12:07 PM, Francesco Montesano
>>> <franz.bergesund@gmail.com> wrote:
>>>> If I use the ? after the command it does as you, but if I use the help
>>>> function (help(range), help(plot)) it prints both texts on the
>>>> console.
>>>> The ? has the same behaviour on the qtconsole and the standard ipython
>>>> terminal, but in the latter the help function opens a pager
>>>> independently of the length of the docstring (and I personally prefer
>>>> this way). Would be hard to give the help the same behaviour?
>>>> I'm tempted to open a feature request in github to pipe the help(...)
>>>> into the pager
>>>
>>> help() is a builtin function in the standard library, we have no
>>> control over it. I'm sure we could monkeypatch our way around it, but
>>> it's not worth the effort: ? is ipython's machinery, and that's where
>>> we focus our efforts.
>>
>> I was hoping that you might be able to "trick" help() into using the
>> qtconsole's pager.  It uses a function in pydoc called getpager() (do
>> "import pydoc" and "pydoc.getpager??" to see it).
>>
>> It looked like it uses the environment variable "PAGER" if it is
>> defined.  The qtconsole seems to have this defined as 'cat'. I thought
>> maybe the qtconsole should be change os.environ["PAGER"] from 'cat' to
>> whatever it uses to emulate less with ? and ?? (what would that be by
>> the way?).  But apparently that's not the issue. getpager() first
>> checks if type(sys.stdout) is types.FileType (in the qtconsole it is
>> IPython.zmq.iostream.OutStream, which assumedly is not something that
>> can be changed).  If it isn't, it just uses the regular
>> sys.stdout.write "pager". So to really trick help(), you'd have to
>> monkeypatch pydoc.getpager.  Or else redefine help() as the same as
>> the regular help() but using the qtconsole pager. Either way, you're
>> changing the built-in directly.
> Looking at the python2.7.3 and 3.2 source, it seems like the problem
> is (even) more complex.
> In pydoc.getpager() after check the type of sys.stdout, the function
> checks if stdin and stdout are interactive
>
> python 2.7
>      |  python3.2
>
> if type(sys.stdout) is not types.FileType:                       |
> if not hasattr(sys.stdout, "isatty"):
>         return plainpager
>    |        return plainpager
>     if not sys.stdin.isatty() or not sys.stdout.isatty():       |
> if not sys.stdin.isatty() or not sys.stdout.isatty():
>         return plainpager
>    |        return plainpager
>
> IPython.zmq.iostream.OutStream has isatty attribute, so requesting to change
> "if type(sys.stdout) is not types.FileType:" to "if not
> hasattr(sys.stdout, "isatty"):" in python 2.7, will make the first
> 'if' to be skipped.
> But in the qtconsole sys.stdout(=IPython.zmq.iostream.OutStream) and
> sys.stdin(=open file '<stdin>', mode 'r') are not interactive (at
> least under 2.7.x)
> In [86]: not sys.stdin.isatty() or not sys.stdout.isatty()
> Out[86]: True
>
> It looks like I'll have to change my habits about help when using the
> ipython afterall, although I don't like too much the fact that ? and
> ?? do not use a pager if the output is shorter than the screen. Is
> there a simple way to use the pager in any case (some rc parameter or
> similar)?

You could just override help() in your IPython profile.  Or monkeypatch pydoc.

I also would like a way to make ? always use a pager (in the regular
console, but I guess it should work everywhere).  The reason is that I
often use / in less to search the docstring.

Aaron Meurer

>
> Cheers,
> Francesco
>
>> If you want, maybe you could open an issue in the CPython bug tracker
>> for a way to enable the pager even when type(sys.stdout) is not
>> FileType.
>>
>> Aaron Meurer
>>
>>>
>>> Cheers,
>>>
>>> f
>>> _______________________________________________
>>> IPython-User mailing list
>>> IPython-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/ipython-user
>> _______________________________________________
>> IPython-User mailing list
>> IPython-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user


More information about the IPython-User mailing list