[Solved] Lists in Python 2.7 (compatible with 3.x)


You need a little more debugging here. For instance, check that your split gives you what you want. Second, please read https://stackoverflow.com/help/mcve — this lists our expectations for posting.

Giving the actual input and error message would have given you an answer much sooner: you fed a list to fnmatch, which expects a string. You’re on the right track, but you can do this more simply.

def success():
    print "good"

def fail():
    print "bad"

list = "10.10.10.127"
fields = list.split(".")

print fields

if len(fields) == 4:
    success()
else:
    fail()

Do you also need to check that each field is entirely numeric?

1

solved Lists in Python 2.7 (compatible with 3.x)