pythonread-eval-print-loop

How to dedent a block in Python3 under MacOS?


I am learning Python3. It is executed on MacOS/Terminal by running python3.
I was able to execute some examples from the book "Deep Learning with Python, Second Edition", but I am stuck now at a simple editor problem:
If I enter the following statements

>>> with tf.GradientTape as tape:
...     tape.watch(input_const)
...     result = tf.square(input_const)
... 

I am not able to terminate the indention block.
If I simply enter return, I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __enter__
>>> 

I have tried to terminate indention using Shift [, Shift tab, and Control [, but this does not work.
How do I dedent a block?

I found a similar question here, but without a solution.


Solution

  • You need to call tf.GradientTape as a function.

    with tf.GradientTape() as tape:
        tape.watch(input_const)
        result = tf.square(input_const)