Not too long ago, I helped someone with some research work, and one of the research tools was also used from the Python interactive prompt.
The interface used was handy enough for development: intuitive, readable, short, and useful. Still, for interactive research it wasn’t handy enough.
To improve the script, I decided to use a trick I heard about a long time ago – using __repr__:
class NoParens(object): def __init__(self, obj): self.obj = obj def __call__(self, *args, **kwargs): return self.obj(*args, **kwargs) def __repr__(self): result = self.obj() return str(result)
And using it looks like this:
In : import noparens In : def test(): ...: return 4**4 ...: In : t = noparens.NoParens(test) In : t Out: 256 In : t,t,t Out: (256, 256, 256)
For research consoles that interact with other programs or devices, such as debuggers and sniffers I found this useful, and made work a bit less annoying.