I am having issues printing out the following dict in my python code.
status = {"1.1.1":"FAIL","1.1.1.1":"FAIL","1.1.1.2":"FAIL","1.1.1.3":"FAIL","1.1.1.4":"FAIL","1.1.1.5":"FAIL","1.1.1.6":"FAIL","1.1.1.7":"FAIL","1.1.1.8":"FAIL","1.1.10":"FAIL","1.1.11":"FAIL","1.1.12":"FAIL","1.1.13":"FAIL","1.1.14":"FAIL","1.1.15":"FAIL","1.1.16":"FAIL","1.1.17":"FAIL","1.1.18":"FAIL","1.1.19":"FAIL","1.1.2":"FAIL","1.1.20":"FAIL","1.1.21":"FAIL","1.1.3":"FAIL","1.1.4":"FAIL","1.1.5":"FAIL","1.1.6":"FAIL","1.1.7":"FAIL","1.1.8":"FAIL","1.1.9":"FAIL","1.2.1":"FAIL","1.2.2":"FAIL","1.3.1":"FAIL","1.3.2":"FAIL","1.4.1":"FAIL","1.4.2":"FAIL","1.4.3":"FAIL","1.5.1":"FAIL","1.5.2":"FAIL","1.5.3":"FAIL","1.5.4":"FAIL","1.6.1":"FAIL","1.6.1.1":"FAIL","1.6.1.2":"FAIL","1.6.1.3":"FAIL","1.6.1.4":"FAIL","1.6.2":"FAIL","1.6.2.1":"FAIL","1.6.2.2":"FAIL","1.6.3":"FAIL","1.7.1":"FAIL","1.7.1.1":"FAIL","1.7.1.2":"FAIL","1.7.1.3":"FAIL","1.7.1.4":"FAIL","1.7.1.5":"FAIL","1.7.1.6":"FAIL","1.7.2":"FAIL","2.1.1":"FAIL","2.1.10":"FAIL","2.1.2":"FAIL","2.1.3":"FAIL","2.1.4":"FAIL","2.1.5":"FAIL","2.1.6":"FAIL","2.1.7":"FAIL","2.1.8":"FAIL","2.1.9":"FAIL","2.2.1.1":"FAIL","2.2.1.2":"FAIL","2.2.1.3":"FAIL","2.2.10":"FAIL","2.2.11":"FAIL","2.2.12":"FAIL","2.2.13":"FAIL","2.2.14":"FAIL","2.2.15":"FAIL","2.2.16":"FAIL","2.2.17":"FAIL","2.2.2":"FAIL","2.2.3":"FAIL","2.2.4":"FAIL","2.2.5":"FAIL","2.2.6":"FAIL","2.2.7":"FAIL","2.2.8":"FAIL","3.1.1":"FAIL","2.3.1":"FAIL","2.3.2":"FAIL","2.3.3":"FAIL","2.3.4":"FAIL","2.3.5":"FAIL","3.1.1":"FAIL","3.1.2":"FAIL","3.2.1":"FAIL","3.2.2":"FAIL","3.2.3":"FAIL","3.2.4":"FAIL","3.2.5":"FAIL","3.2.6":"FAIL","3.2.7":"FAIL","3.2.8":"FAIL","3.3.1":"FAIL","3.3.2":"FAIL","3.3.3":"FAIL","3.4.1":"FAIL","3.4.2":"FAIL","3.4.3":"FAIL","3.4.4":"FAIL","3.4.5":"FAIL","3.5.1":"FAIL","3.5.2":"FAIL","3.5.3":"FAIL","3.5.4":"FAIL","3.6.1":"FAIL","3.6.2":"FAIL","3.6.3":"FAIL","3.6.4":"FAIL","3.6.5":"FAIL","4.1.1.1":"FAIL","4.1.1.2":"FAIL","4.1.1.3":"FAIL","4.1.10":"FAIL","4.1.11":"FAIL","4.1.12":"FAIL","4.1.13":"FAIL","4.1.14":"FAIL","4.1.15":"FAIL","4.1.16":"FAIL","4.1.17":"FAIL","4.1.18":"FAIL","4.1.2":"FAIL","4.1.3":"FAIL","4.1.4":"FAIL","4.1.5":"FAIL","4.1.6":"FAIL","4.1.7":"FAIL","4.1.8":"FAIL","4.1.9":"FAIL","4.2.1.1":"FAIL","4.2.1.2":"FAIL","4.2.1.3":"FAIL","4.2.1.4":"FAIL","4.2.1.5":"FAIL","4.2.2.1":"FAIL","4.2.2.2":"FAIL","4.2.2.3":"FAIL","4.2.2.4":"FAIL","4.2.2.5":"FAIL","4.2.3":"FAIL","4.2.4":"FAIL","5.1.1":"FAIL","5.1.2":"FAIL","5.1.3":"FAIL","5.1.4":"FAIL","5.1.5":"FAIL","5.1.6":"FAIL","5.1.7":"FAIL","5.1.8":"FAIL","5.2.1":"FAIL","5.2.10":"FAIL","5.2.11":"FAIL","5.2.12":"FAIL","5.2.13":"FAIL","5.2.14":"FAIL","5.2.15":"FAIL","5.2.2":"FAIL","5.2.3":"FAIL","5.2.4":"FAIL","5.2.5":"FAIL","5.2.6":"FAIL","5.2.7":"FAIL","5.2.8":"FAIL","5.2.9":"FAIL","5.3.1":"FAIL","5.3.2":"FAIL","5.3.3":"FAIL","5.3.4":"FAIL","5.4.1.1":"FAIL","5.4.1.2":"FAIL","5.4.1.3":"FAIL","5.4.1.4":"FAIL","5.4.2":"FAIL","5.4.3":"FAIL","5.4.4":"FAIL","6.1.1":"FAIL","6.1.10":"FAIL","6.1.11":"FAIL","6.1.12":"FAIL","6.1.13":"FAIL","6.1.14":"FAIL","6.1.2":"FAIL","6.1.3":"FAIL","6.1.4":"FAIL","6.1.5":"FAIL","6.1.6":"FAIL","6.1.7":"FAIL","6.1.8":"FAIL","6.1.9":"FAIL","6.2.1":"FAIL","6.2.10":"FAIL","6.2.11":"FAIL","6.2.12":"FAIL","6.2.13":"FAIL","6.2.14":"FAIL","6.2.15":"FAIL","6.2.16":"FAIL","6.2.17":"FAIL","6.2.18":"FAIL","6.2.19":"FAIL","6.2.2":"FAIL","6.2.20":"FAIL","6.2.3":"FAIL","6.2.4":"FAIL","6.2.5":"FAIL","6.2.6":"FAIL","6.2.7":"FAIL","6.2.8":"FAIL","6.2.9":"FAIL"}
Backstory: I am writing an audit script that creates this dict at the beginning of the script and then updates the values with something like this:
status.get('6.2.4') and status.update({'6.2.4': 'FAIL'}) # # Change value to FAIL
or this one:
status.get('2.2.6') and status.update({'2.2.6': 'PASS'}) # # Change value to PASS
The problem occurs when I try to print out the same dictionary at the end using the following function:
def results():
global failcount
global errcount
for (keys, values) in sorted(status.items()):
print keys + ' ' + values
if values is 'FAIL':
failcount = failcount + 1
if values is 'ERR':
errcount = errcount + 1
print 'IF MORE THAN 3 FAULTS are FOUND please run the script a second time'
The output from running this in my script ends up being:
2.2.11 PASS
5.1.5 PASS
5.2.12 PASS
5.2.13 PASS
5.2.14 PASS
5.2.15 PASS
5.2.2 PASS
5.2.3 PASS
5.2.4 PASS
5.2.5 PASS
5.2.6 PASS
5.2.7 PASS
5.2.8 PASS
5.2.9 PASS
5.3.1 PASS
5.3.2 PASS
5.3.3 PASS
5.3.4 PASS
5.4.1.1 PASS
5.4.1.2 PASS
5.4.1.3 PASS
5.4.1.4 PASS
5.4.2 PASS
5.4.3 PASS
5.4.4 PASS
6.1.1 N/A
6.1.10 PASS
6.1.11 PASS
6.1.12 PASS
6.1.13 PASS
6.1.14 PASS
6.1.2 PASS
6.1.3 PASS
6.1.4 PASS
6.1.5 PASS
6.1.6 PASS
6.1.7 PASS
6.1.8 PASS
6.1.9 PASS
6.2.1 CHK
6.2.10 CHK
6.2.11 PASS
6.2.12 PASS
6.2.13 PASS
6.2.14 PASS
6.2.15 CHK
6.2.16 CHK
6.2.17 CHK
6.2.18 CHK
6.2.19 CHK
6.2.2 PASS
6.2.20 PASS
6.2.3 PASS
6.2.4 PASS
6.2.5 PASS
6.2.6 CHK
6.2.7 CHK
6.2.8 CHK
6.2.9 CHK
IF MORE THAN 3 FAULTS are FOUND please run the script a second time
Faults found: 3
Errors found: 0
Steps I have taken to resolve:
- Ran through Atom python-debugger
- Ran through https://pythoniter.appspot.com/ to verify formatting and spacing.
- Jumped through a number of other questions on here such as How do I sort a list of dictionaries by values of the dictionary in Python? and Iterating over dictionaries using 'for' loops and more.
- Ran through pdb line by line through the function and verified when ran line by line it functioned normally and printed out each value in order.
Used the interpreter to simple create the dictionary and then print it with:
for (keys, values) in sorted(status.items()): print keys + ' ' + values
Which returns this:
1.1.16 FAIL
3.2.6 FAIL
5.1.5 FAIL
5.1.6 FAIL
5.1.7 FAIL
5.1.8 FAIL
5.2.1 FAIL
5.2.10 FAIL
5.2.11 FAIL
5.2.12 FAIL
5.2.13 FAIL
5.2.14 FAIL
5.2.15 FAIL
5.2.2 FAIL
5.2.3 FAIL
5.2.4 FAIL
5.2.5 FAIL
5.2.6 FAIL
5.2.7 FAIL
5.2.8 FAIL
5.2.9 FAIL
5.3.1 FAIL
5.3.2 FAIL
5.3.3 FAIL
5.3.4 FAIL
5.4.1.1 FAIL
5.4.1.2 FAIL
5.4.1.3 FAIL
5.4.1.4 FAIL
5.4.2 FAIL
5.4.3 FAIL
5.4.4 FAIL
6.1.1 FAIL
6.1.10 FAIL
6.1.11 FAIL
6.1.12 FAIL
6.1.13 FAIL
6.1.14 FAIL
6.1.2 FAIL
6.1.3 FAIL
6.1.4 FAIL
6.1.5 FAIL
6.1.6 FAIL
6.1.7 FAIL
6.1.8 FAIL
6.1.9 FAIL
6.2.1 FAIL
6.2.10 FAIL
6.2.11 FAIL
6.2.12 FAIL
6.2.13 FAIL
6.2.14 FAIL
6.2.15 FAIL
6.2.16 FAIL
6.2.17 FAIL
6.2.18 FAIL
6.2.19 FAIL
6.2.2 FAIL
6.2.20 FAIL
6.2.3 FAIL
6.2.4 FAIL
6.2.5 FAIL
6.2.6 FAIL
6.2.7 FAIL
6.2.8 FAIL
6.2.9 FAIL
My next steps:
- Commenting out functions and testing the script to see if a function is outputting incorrectly or if a local function variable is turning global.
- Crying profusely.
My main question is what am I missing in creating the dict or did I loop through it incorrectly?
All of my research and symptoms point to the dict itself being formatted incorrectly, but I can't figure out where I went wrong.
**
RESOLVED
**
Example of the difference between is and == in python.