Python 脚本的 VS Code 中的缩进错误 [英] Indentation error in VS Code for Python script
问题描述
我正在尝试在 VS Code 中运行以下脚本,但是我不断收到缩进错误,这是不言自明的,但我一直无法找到错误?有没有办法在 VS Code 中自动格式化?
I'm trying to run the following script in VS Code, however I keep getting an indentation error, which is kinda self-explanatory, but I haven't been able to find the error? Is there a way auto-formatting in 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)))
我运行脚本时的错误信息:
My error message when I run the script:
[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
更新
我显然混合了制表符和空格.问题已解决.
I mixed tabs and spaces apparently. Issue resolved.
推荐答案
我没有在您的文件中看到任何缩进错误.
I don't see any indentation errors in your file.
是的,您可以尝试使用 VS Code 格式化您的文件.有一个名为 editor.action.formatDocument
的快捷方式.您可以在设置中找到适合您的设置的确切键.
Yes, you can try to format your file using VS Code.
There is a shortcut named editor.action.formatDocument
.
You can find the exact keys for your setup in settings.
在我的例子中是 shift + option (alt) + F
这篇关于Python 脚本的 VS Code 中的缩进错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!