I'm creating my first 'game' using pygame, and would like to add a load file option. The code I have is:
file = input('What save file should be opened? ')
file = file + '.txt'
file = open(file, 'r')
tilemap = file.read()
This works fine, until I get to this line
SCREEN.blit(textures[tilemap[row][column]], (column*TILESIZE, row*TILESIZE))
Where I get a KeyError: '['
This is because the file I open is a list of numbers, but it gets opened as a string - the program reads the '[' as part of a string. I've tried using:
tilemap = file.readlines()
But this gives a list with a string inside. Everything I've seen on the internet is putting strings or integers into a list, not just opening a list. How do I open a list??
EDIT:
The file (.txt) is a list of lists, such as:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]