IPython doesn't return anything from a statement block

Viewed 142

I'm writing statements in IPython which should return something, but they don't. For example:

In [1]: if True: 1

In [2]: for i in [1]: i

Meanwhile in the regular Python interpreter, it works as expected:

>>> if True: 1
... 
1
>>> for i in [1]: i
... 
1

These are contrived examples, but boiled down from things I might write in the interpreter. Here's another example - still contrived, but closer to something I might actually write:

for i in range(0x20, 0x7f): chr(i)

I could use a list comprehension, but it's easier to read with each item on its own line. And I could use print(repr(...)), but that's annoying to type.

Is this behaviour intentional? If yes, what's its purpose? And how do I change it to the same behaviour as the regular Python interpreter?

0 Answers
Related