In an effort to clean up a stretch of code I attempted something like this:
class ClassDirection():
def __init__(self):
pass
def downward(self, x):
print (x)
def upward(self, x):
print (X +1)
def sideways(self, x):
print (x // 2)
directions = []
mustard = ClassDirection()
dicty = {downward:5, upward:7, sideways:9}
for a,b in dicty.items():
direction = mustard.a(b)
directions.append(direction)
Seeing as the word "downward" is understood by python as a name that is undefined, it of course doesn't run giving me the error:
NameError: name 'downward' is not defined
I have 2 questions about this. A) Is there a way to store an undefined "name" in a dictionary without storing it as a string and then reformatting with some kind of crazy hack? B) Is it even possible to "inject" a part of a namespace like this?