Created
September 8, 2012 22:02
-
-
Save jzempel/3680140 to your computer and use it in GitHub Desktop.
Constant Diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def diff(module1, module2): | |
"""Determine the difference in constant definitions between two modules. | |
:param module1: First module with constants. | |
:param module2: Second module with constants. | |
""" | |
_and = {} | |
_or = {} | |
_xor = {module1: {}, module2: {}} | |
for attribute in dir(module1): | |
if attribute == attribute.upper(): | |
constant = getattr(module2, attribute, None) | |
if constant is None: | |
_xor[module1][attribute] = constant | |
elif constant == getattr(module1, attribute): | |
_and[attribute] = constant | |
else: | |
_or[attribute] = constant | |
for attribute in dir(module2): | |
if attribute == attribute.upper(): | |
constant = getattr(module1, attribute, None) | |
if constant is None: | |
_xor[module2][attribute] = constant | |
if constant != getattr(module2, attribute): | |
_or[attribute] = constant | |
return (_and, _or, _xor) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment