In Python 3, if you have a class, like this:
LETTERS = list('abcdefghijklmnopqrstuvwxyz')
class letter:
def __init__(self, name):
self.number = LETTERS.index(name)
self.nextLetter = LETTERS[self.number+1]
self.previousLetter = LETTERS[self.number-1]
and you create an instance of letter, myLetter, like this:
myLetter = letter('c')
In letter, how do I get the variable name? (myLetter in this case)
letter(you should capitalize your class names ->class Letter) calledmyLetterand now are asking how to getmyLetterfromletter?letter, I am trying to getmyLetter.list_of_letters = [letter('a'), letter('b')]ora = b = letter('c'). Which variable name would you expect in those cases? What you're asking for is generally not possible (though you might be able to get what you want by inspecting the stack), and shouldn't be used even if it was possible. Variable names are not data. If you want a mapping from a "name" string to an instance, use a dictionary.