Python 为什么在使用best code editor多次编辑代码后,仍然会出现缩进错误?

Python 为什么在使用best code editor多次编辑代码后,仍然会出现缩进错误?,python,python-3.x,Python,Python 3.x,我使用以下命令行调用了我的脚本python3/home/hironwise/transcribe.py,然后我得到一个错误,指出意外缩进文件“/home/username/transcribe.py”第3行def main() ^ 我使用了VSL代码编辑器,但仍然没有正确使用它 #!/usr/bin/venv python from pathlib import PureWindowsPath path=PureWindowsPath('/Users/Ron/AppData/Loc

我使用以下命令行调用了我的脚本
python3/home/hironwise/transcribe.py
,然后我得到一个错误,指出
意外缩进文件“/home/username/transcribe.py”第3行def main()
^

我使用了VSL代码编辑器,但仍然没有正确使用它

#!/usr/bin/venv python

  from pathlib import PureWindowsPath 
  path=PureWindowsPath('/Users/Ron/AppData/Local/Packages/transcribe.py').is_absolute()

  def transcribe_gcs(gcs_uri):
      gcs_uri = 'gs://appliedlinguistics66/speech/WhyJonyIveisLeavingApple.mp4'

      from google.cloud import speech_v1p1beta1
      from google.cloud.speech_v1p1beta1 import enums
      from google.cloud.speech_v1p1beta1 import types
      client = speech.SpeechClient()
我希望第3行在编辑后正确缩进,但这是我得到的错误:

IndentationError: unexpected indent
File "/home/hironwise/transcribe.py", line 3
   def main():
   ^ "

Python语法需要一致的缩进(例如4个空格或1个制表符空格)才能正确执行程序

请尝试下面的代码

#!/usr/bin/venv python

from pathlib import PureWindowsPath 
path=PureWindowsPath('/Users/Ron/AppData/Local/Packages/transcribe.py').is_absolute()

def transcribe_gcs(gcs_uri):
    gcs_uri = 'gs://appliedlinguistics66/speech/WhyJonyIveisLeavingApple.mp4'

    from google.cloud import speech_v1p1beta1
    from google.cloud.speech_v1p1beta1 import enums
    from google.cloud.speech_v1p1beta1 import types
    client = speech.SpeechClient()

您可能会遇到错误,因为第3行有4个不需要的空格


VSCode有很多可用的格式化程序。我使用。

如果问题格式不正确,则无法帮助解决缩进问题。错误消息显示第3行定义了function main,但显示的代码没有。请显示所显示代码的实际错误。Python不需要四个空格的缩进或单个制表符的缩进,Python需要一致的缩进。两个空格,三个标签,随便什么。它只需要保持一致。@Jeff Dege,谢谢你的留言。编辑了我的答案,现在请看一看。