Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.8K
Visualizações
Match case invalid syntax, but no syntax error without match code

I'm running python 3.9.7 and am making a youtube video info viewer / downloader. Without the match statement the code runs fine and doesn't have any errors with concern to missing brackets. An interesting thing is that Atom doesn't show match with any colour in my code, however it seems not to do that in a blank file with only the match anyway.

# A youtube info and downloader
import getpass

from pytube import YouTube
from pathlib import Path

username = getpass.getuser()
downloads_path = str(Path.home() / "Downloads")

# Create video object
link = input("Enter video link (Don't forget https://): ")
video_object = YouTube(link)

# Print info
print(f"Title:  {video_object.title}")
print(f"Length: {round(video_object.length / 60, 2)} minutes")
print(f"Views:  {round(video_object.views / 1000000, 2)} million")
print(f"Author: {video_object.author}")

# Download
print("Download: (b)est | (w)orst | (a)udio | (e)xit")
download_choice = input(f"{username} $ ")

match download_choice:
    case: "b":
        video_object.streams.get_highest_resolution().download(downloads_path)

    case: "w":
        video_object.streams.get_worst_resolution().download(downloads_path)

    case: "a":
        video_object.streams.get_audio_only().download(downloads_path)

Edit: I'm running it in the terminal

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Had to install python3.10 from python.org because catch matching was only added in python 3.10

over 4 years ago · Santiago Trujillo Relatório

0

When getting invalid syntax error on match statement, check that you have at least python 3.10 installed as this is the version it was released.

You can check your current version

cmd

python -V

python

import sys
print(sys.version)

Install the latest version of python (Windows)
Download installer: https://www.python.org/downloads/

or

Chocolatey update
cmd install chocolatey if not already (paste to admin shell)

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Update python version (3.x)

choco upgrade python3 --pre

Sources:
https://www.delftstack.com/howto/python/how-to-update-python/
https://www.python.org/downloads/
https://docs.chocolatey.org/en-us/choco/setup#install-with-cmd.exe

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda