Saturday, July 28, 2012

Python REPL one-liner (Read-Eval-Print-Loop) by Raymond Hettinger and Cameron Laird

By Vasudev Ram

(Reformatted the stuff below a bit for clarity of the rendered HTML - no material changes made.)

@raymondh (Raymond Hettinger) tweeted:

Fun #python one-liner:
while True: request=raw_input('! '); result=eval(request); print repr(result)
# Read–eval–print_loop (REPL)

@Phaseit (Cameron Laird) replied:

@raymondh #python Why not compose all the evaluations?

I guess Cameron meant this:

while True: print repr(eval(raw_input('! ')))

Nice improvement - makes it a bit more functional) and shorter, without reducing clarity much.

To actually run it, the full command is:

python -c "while True: print repr(eval(raw_input('! ')))"

- Vasudev Ram - Dancing Bison Enterprises

No comments: