WindowsのPythonで「expected an indented block」のエラーが出た際の対応方法について紹介したいと思います。単純に構文内にインデント(段落)が無いことで発生しています。インデントまで見てるんだと感心。
WindowsでPythonを利用できるようにする方法(インストール方法)
WindowsのPythonで「expected an indented block」のエラーが出た際の対応方法
1、Pythonで関数とかを入力していると、「IndentationError: expected an indented block after ‘with’ statement on line 1」のようなエラーが出ることがあります。この解消方法ですが、単純に関数や構文内の記載でインデント(段落)が無いことで発生します。
>>> with open('test.txt', 'w') as f:
... print('test write/nです', file=f)
File "<stdin>", line 2
print('test write/nです', file=f)
^
IndentationError: expected an indented block after 'with' statement on line 1
※上記が例だとすると、printの前に半角スペース(インデント:段落)を入れることで解消します。
>>> with open('test.txt', 'w') as f:
... print('test write/nです', file=f)
...
※上記が例だとすると、printの前に半角スペース(インデント:段落)を入れることで解消します。
コメント