【发布时间】:2020-06-01 09:00:46
【问题描述】:
我正在尝试在 VS Code 中运行以下脚本,但是我不断收到缩进错误,这有点不言自明,但我无法找到错误?有没有办法在 VS Code 中自动格式化?
import logging
import uuid
import json
import azure.functions as func
def main(msg: func.QueueMessage, message: func.Out[func.Document]) -> None:
logging.info('Python queue trigger function processed a queue item: %s', msg_body)
data = json.dumps({
'id': msg.id,
'body': msg.get_body().decode('utf-8'),
'expiration_time': (msg.expiration_time.isoformat()
if msg.expiration_time else None),
'insertion_time': (msg.insertion_time.isoformat()
if msg.insertion_time else None),
'time_next_visible': (msg.time_next_visible.isoformat()
if msg.time_next_visible else None),
'pop_receipt': msg.pop_receipt,
'dequeue_count': msg.dequeue_count
})
message.set(func.Document.from_json(json.dumps(data)))
我运行脚本时的错误信息:
[Running] python -u "c:\Users\artem\Desktop\function\inspariqueuestore\__init__.py"
File "c:\Users\artem\Desktop\function\inspariqueuestore\__init__.py", line 12
data = json.dumps({
^
IndentationError: unexpected indent
[Done] exited with code=1 in 0.093 seconds
更新
我显然混合了制表符和空格。问题已解决。
【问题讨论】:
-
你是否混合了制表符和空格?
-
我不能完全否认我可能无意中混合了它。我会尝试用空格重新格式化它。谢谢
-
@KlausD。重新格式化成功了。谢谢!