2020-10-01 08:41:44 +05:30
# The sys module provides information about constants, functions and methods of the Python interpreter.
2020-05-01 18:52:58 +02:00
import sys
2020-10-01 08:41:44 +05:30
#The len() function returns the number of items in an object. When the object is a string, the len() function returns the number of characters in the string.
2020-05-01 18:52:58 +02:00
argCount = len ( sys . argv ) - 1
if argCount == 1 :
expectedVersion = sys . argv [ 1 ]
versions = len ( expectedVersion . split ( " . " ) )
majorMinor = str ( sys . version_info [ 0 ] ) + ' . ' + str ( sys . version_info [ 1 ] )
if versions == 2 :
# Test only major and minor version
if expectedVersion != majorMinor :
raise Exception ( " Incorrect major + minor version detected \n Expected: " + expectedVersion + " \n Actual: " + majorMinor )
elif versions == 3 :
# Test major, minor and micro version
majorMinorMicro = majorMinor + ' . ' + str ( sys . version_info [ 2 ] )
if expectedVersion != majorMinorMicro :
raise Exception ( " Incorrect major + minor + micro version detected \n Expected: " + expectedVersion + " \n Actual: " + majorMinorMicro )
else :
raise Exception ( " Incorrect number of arguments supplied " )
print ( " Correct version of Python " + expectedVersion + " detected " )
else :
2020-10-01 08:41:44 +05:30
raise Exception ( " Incorrect number of arguments supplied " )