I want to try and remove the quotes from my 2D array of lists but nothing is working, I've tried csv and the standard python functions but nothing appears to be working!!! Here's my code so far:
with open('level1.txt', 'r') as file:
fileArr = file.readlines()
fileArr = [[int(item) for item in line.rstrip("\n").split(",")] for line in fileArr]
level.append(fileArr)
print(str(level))
And here is what it outputs:
[[['platforms.GRASS_LEFT', '500', '500'], ['platforms.GRASS_MIDDLE', '570', '500'], ['platforms.GRASS_RIGHT', '640', '500'], ['platforms.GRASS_LEFT', '800', '400'], ['platforms.GRASS_MIDDLE', '870', '400'], ['platforms.GRASS_RIGHT', '940', '400'], ['platforms.GRASS_LEFT', '1000', '500'], ['platforms.GRASS_MIDDLE', '1070', '500'], ['platforms.GRASS_RIGHT', '1140', '500'], ['platforms.STONE_PLATFORM_LEFT', '1120', '280'], ['platforms.STONE_PLATFORM_MIDDLE', '1190', '280'], ['platforms.STONE_PLATFORM_RIGHT', '1260', '280'], ['platforms.GRASS_LEFT_BOTTOM', '-150', '600'], ['platforms.GRASS_LEFT', '535', '200'], ['platforms.GRASS_MIDDLE', '605', '200'], ['platforms.GRASS_RIGHT', '675', '200']]]
And finally this is what I want to be outputted:
[ [platforms.GRASS_LEFT, 500, 500],
[platforms.GRASS_MIDDLE, 570, 500],
[platforms.GRASS_RIGHT, 640, 500],
[platforms.GRASS_LEFT, 800, 400],
[platforms.GRASS_MIDDLE, 870, 400],
[platforms.GRASS_RIGHT, 940, 400],
[platforms.GRASS_LEFT, 1000, 500],
[platforms.GRASS_MIDDLE, 1070, 500],
[platforms.GRASS_RIGHT, 1140, 500],
[platforms.STONE_PLATFORM_LEFT, 1120, 280],
[platforms.STONE_PLATFORM_MIDDLE, 1190, 280],
[platforms.STONE_PLATFORM_RIGHT, 1260, 280],
[platforms.GRASS_LEFT_BOTTOM,-150,600],
[platforms.GRASS_LEFT,535,200],
[platforms.GRASS_MIDDLE,605,200],
[platforms.GRASS_RIGHT,675,200],
]
Any help would be much appreciated to help stopping me having a mental breakdown.
int( "platforms.GRASS_LEFT" )(line 3) will fail. Theint()is not there in the version that produces a list of list of strings right?