Why am I not able to put an object into a list?

63 Views Asked by At

I'm using replit for my programming here, and am trying to put an object into a list. When I try and make a new game to update my data to the default data, it tells me ValueError: Circular reference detected., and I am not entirely sure what this means. The replit in question is this. It only ever happens when I try and add an object into the list. Does anyone know why this is happening?

Edit: This is the class:

class Lemon:
  def __init__(self, _type, _rating):
    self.type = _type
    self.rating = _rating

  def typeText(self):
    # basic lemons
    if self.type == 0:
      return 'Basic lemon'
    elif self.type == 1:
      return 'Happy lemon'
    elif self.type == 2:
      return 'Sad lemon'
    elif self.type == 3:
      return 'Hasty lemon'
    elif self.type == 4:
      return 'Cool lemon'
    # rare lemons
    elif self.type == 5:
      return '[gold3]Fire lemon[/gold3]'
    elif self.type == 6:
      return '[gold3]Ice lemon[/gold3]'
    elif self.type == 7:
      return '[gold3]Tired lemon[/gold3]'
    elif self.type == 8:
      return '[gold3]Shocked lemon[/gold3]'
    elif self.type == 9:
      return '[gold3]Bored lemon[/gold3]'
    # epic lemons
    elif self.type == 10:
      return '[green]Caveman lemon[/green]'
    elif self.type == 11:
      return '[green]Future lemon[/green]'
    elif self.type == 12:
      return '[green]Alien lemon[/green]'
    elif self.type == 13:
      return '[green]Liquid lemon[/green]'
    # legendary lemons
    elif self.type == 14:
      return '[cyan]Cat lemon[/cyan]'
    elif self.type == 15:
      return '[cyan]Dog lemon[/cyan]'
    elif self.type == 16:
      return '[cyan]Earth lemon[/cyan]'
    # mythic lemons
    elif self.type == 17:
      return '[blue]Water lemon[/blue]'
    elif self.type == 18:
      return '[blue]Air lemon[/blue]'
    # magical lemons
    elif self.type == 19:
      return '[magenta]Elemental lemon[/magenta]'
  def show(self, bare=True):
    if bare:
      return self.typeText()
    else:
      return f'{self.typeText()} with a rating of {self.rating}'

and here is where I set the default data:

defaultData = {'money': 0,
              'lemons': [Lemon(1, 1)]}

Hope this helps!

0

There are 0 best solutions below