Reputation: 189
I am trying to exit the program if the value is not what I want but it doesn't do anything. What seems to be the problem? I think it stops the program but does not print "Invalid Subnet Mask".
from sys import exit
def maskvalidation(mask):
string = mask.split(".")
toInt = [int(i) for i in string]
binary = [bin(x) for x in toInt]
purebin = []
for x in binary:
purebin.append(x[2:])
if purebin[0] == "11111111":
print("good")
else:
exit("Invalid Subnet Mask")
maskvalidation("251.0.0.0")
Upvotes: 0
Views: 119
Reputation: 304167
help for sys.exit
exit(...) exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is an integer, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure).
So it is being used correctly in the question.
Furthermore, your sample program works fine for me on linux for Python2.7 and Python3.4.
It does however send the output to stderr
rather than stdout
, so perhaps that is the problem you are seeing
Upvotes: 2