[英]IndentationError - expected an indented block
我得到 IndentationError: expected an indented block。 我試圖將網頁中的所有內容復制到 txt 文件中。 不確定錯誤是什么,但在我的作業中發現如果有空格和制表符的組合,則會出現縮進錯誤。 有人可以從 python 開始提供幫助。 提前致謝。
import requests
url = 'https://seekingalpha.com/article/4166013-t-t-q1-2018-results-earnings-call-transcript?part=single'
data = requests.get(url)
with open('file.txt','w') as out_f:
out_f.write(data.text.encode('utf-8'))
with
預期的縮進塊是跟隨,所以這樣做:
with open('file.txt','w') as out_f:
out_f.write(data.text.encode('utf-8'))
這與縮進if
、 elif
、 else
、 for
、 while
、 try
等時的情況相同。
與許多其他語言不同,Python 使用縮進來創建代碼塊。 Python 代碼塊通常用 4 或 8 個空格縮進。 在復制/粘貼時,您應該注意您在網上找到的代碼的縮進。 綜上所述,從 Internet 上復制/粘貼隨機代碼是在實驗室作業中獲得病毒或 0 的好方法。
以下是有關 Python 縮進的更多詳細信息: https : //www.python-course.eu/python3_blocks.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.