Skip to content

Instantly share code, notes, and snippets.

@Sirsirious
Last active February 4, 2020 17:32
Show Gist options
  • Save Sirsirious/6f3500aedabfeacd97db2ccf4438ae14 to your computer and use it in GitHub Desktop.
Save Sirsirious/6f3500aedabfeacd97db2ccf4438ae14 to your computer and use it in GitHub Desktop.
How to deal with printing and comparison with a reference-based system.
#[...]
def get(self):
if self.SOS:
return '<SOS>'
elif self.EOS:
return '<EOS>'
else:
return self._sentence_string[self.start_pos:self.end_pos]
# Displays the Token value in the terminal if the variable is called
def __repr__(self):
return self.get()
# Displays the Token value to the stdout
def __str__(self):
return self.get()
# Compares one token to other in a simple string-based fashion.
def __eq__(self, other):
return self.get() == other
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment