In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to test the Python version at run time, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Detect the Python version at run time
Sometimes, if the currently running Python engine is lower than the supported version, we may not want to execute our program. To do this, you can use the following code snippet. It also prints the version of Python currently in use in a readable format.
Import sys#Detect the Python version currently in use.if not hasattr (sys, "hexversion") or sys.hexversion! = 50660080: print ("Sorry, you aren't running on Python 3.5\ n") print ("Please upgrade to 3.5.\ n") sys.exit (1) # Print Python version in a readable format.print ("Current Python version:", sys.version)
Alternatively, you can replace sys. Hexversioncodes = 50660080 with sys.version_info > = (3,5) in the above code. This is the advice of an informed reader.
Output at run time on Python 2.7s.
Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.8.2] on linux Sorry, you aren't running on Python 3.5Please upgrade to 3.5.
Output at run time on Python 3.5.
Python 3.5.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux Current Python version: 3.5.2 (default, Aug 22 2016, 21:11:05) [GCC 5.3.0] Thank you for reading this article carefully. I hope the article "how to detect the Python version at run time" shared by the editor will be helpful to you. At the same time, I hope you will support me and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
How to use Android AS to create a custom layout, for this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way. First create a title.xml
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.