File size: 995 Bytes
f17b878 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # Check the latest stable Python version
import subprocess
def get_latest_python_version():
"""
Get the latest stable Python version from the official Python website.
Returns:
str: The latest stable Python version.
"""
try:
result = subprocess.run(['curl', '-s', 'https://www.python.org/downloads/'], capture_output=True, text=True)
output = result.stdout
# Extract the latest version from the HTML content
import re
match = re.search(r'Latest Python 3 Release - Python (\d+\.\d+(\.\d+)?)', output)
if match:
return match.group(1)
else:
raise ValueError("Could not find the latest Python version.")
except Exception as e:
print(f"Error fetching the latest Python version: {e}")
return None
if __name__ == "__main__":
latest_version = get_latest_python_version()
if latest_version:
print(f"The latest stable Python version is: {latest_version}") |