Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to detect the Python version at run time

2025-01-17 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report