1

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:\pythonProject\monop\propertyinfo.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:\monop\car.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.

1 Answers1

1

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

x = int(temp[12])
y = int(temp[13])
Rabbid76
  • 202,892
  • 27
  • 131
  • 174