title: How do I use a keyword as a variable name?
body: <p>I have the following class with the variables <code>from</code>, <code>to</code> and <code>rate</code>. <code>from</code> is a <a href="https://docs.python.org/3/reference/lexical_analysis.html#keywords" rel="nofollow noreferrer">keyword</a>. If I want to use it in the init method below, what's the correct way to write it?</p>
  <p>More context: The class needs the <code>from</code> variable explicitly as it's part of a json required by a POST endpoint written up by another developer in a different language. So changing the variable name is out of the question.</p>
  <pre><code>class ExchangeRates(JsonAware):
      def __init__(self, from, to, rate):
          self.from = from
          self.to = to
          self.rate = rate
  </code></pre>
  <p>JsonAware code:</p>
  <pre><code>class PropertyEquality(object):
      def __eq__(self, other):
          return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__)
  
      def __ne__(self, other):
          return not self.__eq__(other)
  
      def __repr__(self):
          return '%s(%s)' % (self.__class__.__name__, ', '.join(['%s=%s' % (k, v) for (k, v) in self.__dict__.items()]))
  
  class JsonAware(PropertyEquality):
      def json(self):
          return json.dumps(self, cls=GenericEncoder)
  
      @classmethod
      def from_json(cls, json):
          return cls(**json)
  </code></pre>
  <p>GenericEncoder code:</p>
  <pre><code>class GenericEncoder(json.JSONEncoder):
      def default(self, obj):
          return obj.__dict__
  </code></pre>