Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.8K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda