I am an engineer and I use a python REPL as an advanced calculator while working. I use the "previous output" feature of the REPL, which is _, often.
>>>45*0.344
15.48
>>>_*2
30.96
Something like that.
For some reason I find it kind of a chore to type the underscore though. I've used the Haskell REPL, which uses "it" as the previous output variable, which I find easier to type.
I learned that iPython lets you define macros that execute some code. So I popped open an iPython shell and defined a %macro called "it" that mimics the "_".
In [1]: _
Out[1]: ''
In [2]: %macro it 1
Macro `it` created. To execute, type its name (without quotes).
=== Macro contents: ===
_
I can call "it" like so:
In [1]: 4
Out[1]: 4
In [2]: it
Out[2]: 4
However, when I try to do something with "it" like it*4
, I get the error unsupported operand type(s) for *: 'Macro' and 'int'
.
I want "it" to be the type it's returning instead of the type Macro, so that I can use it just like I use "_".