[Tutor] dictionaries are same but returning false
Danny Yoo
dyoo at hashcollision.org
Wed Jul 5 15:01:00 EDT 2017
The difflib library (https://docs.python.org/2/library/difflib.html)
can also help with some exploratory discovery of the problem.
Here's an example:
####################################################
>>> import difflib
>>> for line in difflib.context_diff(repr(x).split(','), repr(y).split(',')):
... print line
...
***
---
***************
*** 1,7 ****
{'_icmp_options': None
'_tcp_options': {'source_port_range': None
! 'destination_port_range': {'max': '22'
! 'min': '22'}}
'_protocol': '6'
'swagger_types': {'protocol': 'str'
'tcp_options': 'TcpOptions'
--- 1,7 ----
{'_icmp_options': None
'_tcp_options': {'source_port_range': None
! 'destination_port_range': {'max': 22
! 'min': 22}}
'_protocol': '6'
'swagger_types': {'protocol': 'str'
'tcp_options': 'TcpOptions'
####################################################
To make the diff comprehensible, we're splitting by commas and
comparing each comma-delimited chunk between the representations of x
and y. We got lucky here because the dictionaries are printing their
values in the same order here. Normally we should not depend on this
kind of behavior, but we're just doing exploratory programming, so no
foul. :P
More information about the Tutor
mailing list