For the history command, in particular, the simplest solution is
In [243]: history -t -f history.txt In [244]: with open('history.txt') as f: .....: HIST = [l.strip() for l in f] .....: In [245]: len(HIST) Out[245]: 258 In [246]: HIST[-1] Out[246]: "get_ipython().magic(u'history -t -f history.txt')" In [247]:
Basically, upload it to a file and read it back.
It may seem kludge, but I suspect that it comes from the nature of IPython. This is actually not an interpreter, but instead a command-line shell for the interpreter. My suspicion is that magic commands are processed internally by IPython and do not go the usual way of passing commands to the interpreter, capturing the output and storing it in the command history as Out [n]. Therefore, it is not available for call and destination.
An alternative is that get_ipython().magic just returns None .
In any case, the d = screen output for %history not available. You must dump it to a file.
It seems that he is changing to a magic team. alias , for example, returns screen output
In [288]: a=%alias Total number of aliases: 17 In [289]: a Out[289]: [('cat', 'cat'), ('clear', 'clear'), ('cp', 'cp'), ('ldir', 'ls -F -G -l %l | grep /$'), ('less', 'less'), ('lf', 'ls -F -l -G %l | grep ^-'), ('lk', 'ls -F -l -G %l | grep ^l'), ('ll', 'ls -F -l -G'), ('ls', 'ls -F -G'), ('lx', 'ls -F -l -G %l | grep ^-..x'), ('man', 'man'), ('mkdir', 'mkdir'), ('more', 'more'), ('mv', 'mv'), ('rm', 'rm'), ('rmdir', 'rmdir'), (u'show', u'echo')] In [290]: