- Operating System: Windows, 64bit
- Python Version: 3.7.11
- IDE: Jupyter Notebook (with conda env)
I have below code:
class Vocabulary(object):
PAD_token = 0
def __init__(self):
self.index2word = {PAD_token: "PAD"}
# create object
voc = Vocabulary()
I want to use PAD_token class variable inside __init__ method but I got below error:
NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_8472/897996601.py in <module>
----> 1 voc = Vocabulary()
~\AppData\Local\Temp/ipykernel_8472/3780152240.py in __init__(self)
4
5 def __init__(self):
----> 6 self.index2word = {PAD_token: "PAD", SOS_token: "SOS", EOS_token: "EOS"}
NameError: name 'PAD_token' is not defined
Question:
- How can I use
PAD_tokenclass variable inside__init__or other methods of the class?