[IPython-dev] %r vs %rep

Fernando Perez fperez.net at gmail.com
Fri Sep 7 13:46:28 EDT 2007

On 9/7/07, Ville M. Vainio <vivainio at gmail.com> wrote:
> >From changelog, regarding %r magic:
> """
>  No, "up + enter. One char magic" is not
>         the same thing, since %r takes parameters to allow fast retrieval
>         of old commands.  I've received emails from users who use this a
>         LOT, so it stays.
> """
> The new %rep magic does the same thing much better

No, not *much better*.  Differently, with other good, but
non-overlapping functionality.  But there's a rapid, efficient, useful
behavior of %r that some users rely on that %rep does not provide, at
least not at the moment. %rep doesn't immediately execute, which is a
feature of %r:

In [20]: print 99

In [21]: r
Executing: print 99

Instead, using %rep:

In [20]: print 99

In [21]: r
Executing: print 99

In [23]: rep 20

In [24]: %rep 20

In [25]: print 10

In [26]: rep

In [27]:

Why isn't it executing at all?

%rep also doesn't put the last line of input, but *output*:

In [30]: l = ['hei','vaan']

In [31]: ''.join(l)
Out[31]: 'heivaan'

In [32]: rep

In [33]: heivaan

at the editing prompt.  That's useful, but not the same thing.

> I think it should me mentioned in the docsting of %r, at least.

Agreed.  They cover similar, related functionality: %r is immediate
repetition with minimal matching, %rep allows re-editing.

I'd still like to know what's going on with the above, since the docstring says

    Place a string version of last input to the next input prompt. Allows you
    to create elaborate command lines without using copy-paste::

but it seems to put the output instead.  Am I confused?



More information about the IPython-dev mailing list