Trying to figure out this why I'm getting this error about not declaring a variable.
this works fine:
def findLargestIP():
for i in tagList:
#remove all the spacing in the tags
ec2Tags = i.strip()
#seperate any multiple tags
ec2SingleTag = ec2Tags.split(',')
#find the last octect of the ip address
fullIPTag = ec2SingleTag[1].split('.')
#remove the CIDR from ip to get the last octect
lastIPsTag = fullIPTag[3].split('/')
lastOctect = lastIPsTag[0]
ipList.append(lastOctect)
largestIP = int(ipList[0])
for latestIP in ipList:
if int(latestIP) > largestIP:
largestIP = latestIP
# return largestIP
print largestIP
In the list of number tags the largest # is 16 and it outputs :
python botoGetTags.py
16
But the above only printed out the variable I need to pass that on to another function but when I modify the code above
return largestIP
# print largestIP
And call the function:
return largestIP
#print largestIP
findLargestIP()
print largestIP
I get this error :
python botoGetTags.py
Traceback (most recent call last):
File "botoGetTags.py", line 43, in <module>
print largestIP
NameError: name 'largestIP' is not defined
My guess is I have to initialize the variable in global.. But when I do that by making largestIP = 0, it returns 0 instead of the value that is in the function
Thanks!