title: How to fix 'RecursionError: maximum recursion depth exceeded' when calling object?
body: <p>I'm trying to save instances of classes to strings in Python 3.7.</p>
  
  <p>I'm trying this because I've started to make a text-based game that has a dictionary of co-ordinates and instances of classes for the world (I followed this tutorial: <a href="https://letstalkdata.com/2014/08/how-to-write-a-text-adventure-in-python/" rel="nofollow noreferrer">https://letstalkdata.com/2014/08/how-to-write-a-text-adventure-in-python/</a>) and I want to add a save option. If you just pickle the world dictionary it said where in the RAM the rooms were, which wasn't very helpful. But then I read about <code>repr()</code> and <code>exec()</code> somewhere and I am now trying to use it to save and load instances of a test class. But when I try to print my  newly created instance of the class it gives me a <code>RecursionError: maximum recursion depth exceeded</code>.</p>
  
  <pre class="lang-python prettyprint-override"><code>
  import traceback
  
  def change_char(s, p, r):
      l = list(s)
      l[p] = r
      return "".join(l)
  
  class Class:
      def __init__(self, i1, i2, *i3):
          (filename,line_number,function_name,text)=traceback.extract_stack()[-2]
          self.name = text[:text.find('=')].strip()
          self.i1 = i1
          self.i2 = i2
          self.i3 = []
          for iv in i3:
              self.i3.append(iv)
  
      def l(self, l):
          s = ''
          i = 1
          for e in l:
              if i &lt; len(l):
                  s = s + repr(e) + ", "
              else:
                  s = s + repr(e)
              i += 1
          return s
  
      @property
      def print_vals(self):
          print('i1 : {1}\ni2 : {2}\ni3 : {3}'.format(self.i1, self.i2, self.l(self.i3)))
  
      def __repr__(self):
          return '{0} = Class({1}, {2}, {3})'.format(self.name, repr(self.i1), repr(self.i2), self.l(self.i3))
  
      @property
      def save(self):
          return repr(self)
  
  def Classload(st):
      name = st[:st.find('=')].strip()
      exec('global '+name+'\n'+st)
      exec('global '+name+'\n'+name+'.name = '+name)
  
  c = Class(1, "str", "Hello", 'world!')
  
  print(repr(c))
  i = c.save
  i = change_char(i, 0, 'i')
  print(i)
  Classload(i)
  print(c)
  print(i)
  print(repr(c))
  print(repr(i))
  </code></pre>
  
  <p>I expect the output to be:</p>
  
  <pre><code>c = Class(1, 'str', 'Hello', 'world!')
  i = Class(1, 'str', 'Hello', 'world!')
  c = Class(1, 'str', 'Hello', 'world!')
  i = Class(1, 'str', 'Hello', 'world!')
  c = Class(1, 'str', 'Hello', 'world!')
  i = Class(1, 'str', 'Hello', 'world!')
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>c = Class(1, 'str', 'Hello', 'world!')
  i = Class(1, 'str', 'Hello', 'world!')
  c = Class(1, 'str', 'Hello', 'world!')
  Traceback (most recent call last):
    File "C:\Users\HP\Desktop\test.py", line 107, in &lt;module&gt;
      print(i)
    File "C:\Users\HP\Desktop\test.py", line 63, in __repr__
      return '{0} = Class({1}, {2}, {3})'.format(self.name, repr(self.i1), repr(self.i2), self.l(self.i3))
    File "C:\Users\HP\Desktop\test.py", line 63, in __repr__
      return '{0} = Class({1}, {2}, {3})'.format(self.name, repr(self.i1), repr(self.i2), self.l(self.i3))
    File "C:\Users\HP\Desktop\test.py", line 63, in __repr__
      return '{0} = Class({1}, {2}, {3})'.format(self.name, repr(self.i1), repr(self.i2), self.l(self.i3))
    [Previous line repeated 245 more times]
  RecursionError: maximum recursion depth exceeded
  </code></pre>
  
  <p>How do I fix this?</p>