A briefer way to get the latest version number of Python
See original GitHub issueIn gibMacOS.bat
and MakeInstall.bat
, the latest version number of Python ( variable %release%
) was got by several steps:
- Save web page Python Releases for Windows as
pyurl.txt
; - Find the line which contains “Latest Python 3 Release”;
- 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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks again for the suggestion - I pushed it in the latest commit.
-CorpNewt
Sorry, I just learned that there can be more than one delimiters after
delims=
. So things can be done in a single line: