Skip to content

Instantly share code, notes, and snippets.

@lordlycastle
Last active February 8, 2019 13:19
Show Gist options
  • Save lordlycastle/6fa9b4c15fa6988eb93575f0232dd903 to your computer and use it in GitHub Desktop.
Save lordlycastle/6fa9b4c15fa6988eb93575f0232dd903 to your computer and use it in GitHub Desktop.
# Example class
class Eg(object):
a = None
def __init__(self, a):
self.a = a
# look up dict to connect attribute to keys so I can get the relavent attr based on the key.
# issue is that it is easy to make mistake in string since there's no auto-complete and IDE checking.
# and obviously it's annoying to use. I
lookup_dict = {1: lambda eg: eg.a}
# Example usage implementation (not real!!!)
eg = Eg(10)
for k,v in lookup_dict.items():
x = lookup_dict[k](eg)
#....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment