question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A briefer way to get the latest version number of Python

See original GitHub issue

In gibMacOS.bat and MakeInstall.bat , the latest version number of Python ( variable %release% ) was got by several steps:

  1. Save web page Python Releases for Windows as pyurl.txt;
  2. Find the line which contains “Latest Python 3 Release”;
  3. Get the version number from this line. https://github.com/corpnewt/gibMacOS/blob/ce6f62c388f2bd48ec57aeca057e29ff90406dbb/gibMacOS.bat#L87-L124

Here I offer a briefer way to do that: ( Copy the following code as test.bat and try to run it)

@echo off
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','pyurl.txt')"

:: The output of 'findstr /n /i /c:"Latest Python 3 Release" pyurl.txt' should be like: 
::     503:            <li><a href="/downloads/release/python-374/">Latest Python 3 Release - Python 3.7.4</a></li>
for /f "tokens=9 delims= " %%x in ('findstr /n /i /c:"Latest Python 3 Release" pyurl.txt') do ( set release="%%x")
:: %%x is like: 3.7.4</a></li>
:: Use ` set release="%%x" ` instead of ` set "release=%%x" `, since %%x contains '<' and '>'
:: And now %release% is "3.7.4</a></li>" , containing "" , so next command should not be:
:: for /f "tokens=1 delims=<" %%x in ("%release%") do ( set "release=%%x" )
:: no additional ""
for /f "tokens=1 delims=<" %%x in (%release%) do ( set "release=%%x" )

echo release: %release%
REM del pyurl.txt
pause

Only two commands are needed to get the %release% . ( The /n option of command findstr , which shows additional line number 503, is not essential.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
corpnewtcommented, Sep 13, 2019

Thanks again for the suggestion - I pushed it in the latest commit.

-CorpNewt

0reactions
LussacZhengcommented, Sep 13, 2019

Sorry, I just learned that there can be more than one delimiters after delims= . So things can be done in a single line:

@echo off
powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','pyurl.txt')"

:: <li><a href="/downloads/release/python-374/">Latest Python 3 Release - Python 3.7.4</a></li>
for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python 3 Release" pyurl.txt') do ( set "release=%%x" )
:: or
REM for /f "tokens=10 delims=< " %%x in ('findstr /n /i /c:"Latest Python 3 Release" pyurl.txt') do ( set "release=%%x" )

echo release: %release%
echo https://www.python.org/ftp/python/%release%/python-%release%-amd64.exe
REM del pyurl.txt
pause
Read more comments on GitHub >

github_iconTop Results From Across the Web

Check the version of Python package/library - nkmk note
This article describes how to check the version of packages (libraries) and modules used in Python scripts, and the version of packages ...
Read more >
How do I get a python module's version number through code?
Use pkg_resources(part of setuptools). Anything installed from PyPI at least has a version number. No extra package/module is needed.
Read more >
Pip Install Specific Version of a Python Package: 2 Steps
In this tutorial, you will learn how to use pip to install a specific version of a Python package. Here you will learn...
Read more >
Installing Python Modules (Legacy version) — Python 3.11.1 ...
If all these things are true, then you already know how to build and install the modules you've just downloaded: Run the command...
Read more >
How can I determine the current version number ... - Super User
apt-get is the wrong tool for that. dpkg -l python-twisted shows the version number as part of a human-friendly listing with possibly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found