为什么在用最好的代码编辑器编辑了我的代码几次之后,我仍然得到缩进错误?

2024-10-03 13:27:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我用下面的命令行调用了我的脚本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():
   ^ "

Tags: frompyimportcloudhomedef错误google
1条回答
网友
1楼 · 发布于 2024-10-03 13:27:36

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

相关问题 更多 >