获取python的版本&获取两个日期的天数差值


import sys

from datetime import datetime

# Syntax sugar.
_ver = sys.version_info # 获取python版本

#: Python 2.x?
is_py2 = (_ver[0] == 2) # is_py2 类型为布尔型,返回 False 或 True

#: Python 3.x?
is_py3 = (_ver[0] == 3)

retire_day = datetime(2020, 1, 1)
today = datetime.now()
left_days = (retire_day - today).days # 获取两个日期的天数差值

if left_days > 0:
retire_msg = "Python 2 will retire in {} days, why not move to Python 3?".format(left_days)
else:
retire_msg = "Python 2 has been retired, you should move to Python 3."

print(_ver, "\n", is_py2, is_py3)
print(retire_msg)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM