Invalid rect assignment

Question:

I have a class in which I am trying to create a new method move_piece() . Here is my current code:

def move_piece(self):
      propinfo = open('D:pythonProjectmonoppropertyinfo.txt')
      propinfolines = propinfo.readlines()

      temp = (propinfolines[self.squareID + 1].split(',')) # ^ all code above this is simply reading a specific line from a text file , and splitting it into an array by a delimited character (,)
      print('x = ' + temp[12])
      print('y = ' + temp[13]) # these two lines here are simply to print the new x and y value to the console to make sure I have the correct values.
      x = temp[12]
      y = temp[13]
      self.rect.y = y
      self.rect.x = x

When I run the code , I get the following error :

File "D:monopcar.py", line 38, in move_piece
    self.rect.x = x
TypeError: invalid rect assignment

I am unsure why , from what I read you cannot assign a value to a rect directly from an array , hence the reason I passed it to a variable first. But it still isn’t working. Thank you for any help.

Asked By: Freddie Moore

||

Answers:

temp is a string you have to convert the string to an integral value:

x = int(temp[12])
y = int(temp[13])
Answered By: Rabbid76
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.