Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.8K
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!