N
N
Nikita Batenko2019-08-15 11:17:54
Python
Nikita Batenko, 2019-08-15 11:17:54

How to fix AttributeError: 'Field' object has no attribute 'spritedict' errors if it only occurs when checked by the debugger?

Hello! As a school project, I am creating a game in python 3.7.1 using pygame. I'm trying to make the "stone" fall down in the field with cells. A field consists of a group (a descendant of the pygame.sprite.Group class) with "strings" (also a descendant of pygame.sprite.Group) that contain "cells" (a descendant of pygame.sprite.Sprite). Each cell has its own row number and the row number to which it belongs.
To recreate cells in the field and lines, methods are provided for changing the type of cells, for example, from empty to wall or stone. Oddly enough, but when recreating a cell, their numbering gets lost, although this should not happen.
But the problem is not entirely in this: when trying to trace the source of the error through the debugger, it, going into the wilds of Pygame, gives this:

AttributeError: 'Field' object has no attribute 'spritedict'

Here is the full text of the error:
Traceback (most recent call last):
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 260, in <module>
    field1 = Field(2,2,100,100,'e')
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 193, in __init__
    self.f_width = width
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 193, in __init__
    self.f_width = width
  File "D:\Python 3.7.1\lib\bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "D:\Python 3.7.1\lib\bdb.py", line 112, in dispatch_line
    self.user_line(frame)
  File "D:\Python 3.7.1\lib\idlelib\debugger.py", line 24, in user_line
    self.gui.interaction(message, frame)
AttributeError: 'Field' object has no attribute 'spritedict'

Moreover, this does not interfere with the launch of the program itself, but the debugger gives an error when checking.
If anyone has experienced this, please advise what can be done. I don’t throw off the code of the program itself, because there are 300+ lines and everything is tied to inheritance.
Thanks in advance.
PS Similar error:
Traceback (most recent call last):
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 271, in <module>
    field1.Column_Remake(2,3,9,1,'e')
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 235, in Column_Remake
    self.line_list[self.counter].Slice_Remake(self.column_number,self.column_number,self.vert_interval,self.column_mat)
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 187, in Slice_Remake
    self.Cell_Remake(self.count,self.slice_mat)
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 176, in Cell_Remake
    self.cell_list[self.position] = Cell(CELL_SIZE[0],CELL_SIZE[1],self.placex + self.position * GAP_X,self.placey,self.position,self.number,self.new_material)
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 28, in __init__
    self.line_number = line_number
  File "D:\Python 3.7.1\Workshop\Проект - 10-11 классы\game v.2.py", line 28, in __init__
    self.line_number = line_number
  File "D:\Python 3.7.1\lib\bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "D:\Python 3.7.1\lib\bdb.py", line 112, in dispatch_line
    self.user_line(frame)
  File "D:\Python 3.7.1\lib\idlelib\debugger.py", line 24, in user_line
    self.gui.interaction(message, frame)
AttributeError: 'Cell' object has no attribute '_Sprite__g'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question