为什么使用最佳代码编辑器多次编辑代码后,我仍然出现缩进错误?

问题描述 投票:-2回答:1

我使用以下命令行python3 /home/hironwise/transcribe.py调用了脚本,然后出现此错误,指出unexpected indent File "/home/username/transcribe.py" line 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-3.x
1个回答
0
投票

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格式化程序。我使用autopep8

© www.soinside.com 2019 - 2024. All rights reserved.