0

hi,

I'm creating a game with pygame and i want to create a matrix that will represent the map(where each tile will be).
my pygame code is ok, because if i create the map without loading the tilemap (the matrix file) the game runs ok.
that would be good but I want to be able to create more than one map.
I created a code to generate a map matrix file

#MAP GENERATOR

import pickle

tilemap = []
for y in range(100):
    tilemap.append([])
    for x in range(100):
        tilemap[y].append(1)

file = open('data/tilemap2.txt', 'w+b')
pickle.dump(tilemap, file)

file.close()

but when I try to open i get this

Traceback (most recent call last):
File "C:\Users\Mateus\Desktop\Martial Arts\Martial Arts1.py", line 6, in <module>
tilemap = pickle.load('data/tilemap2.txt')
File "C:\Python31\lib\pickle.py", line 1365, in load
encoding=encoding, errors=errors).load()
AttributeError: 'str' object has no attribute 'readline'

here is the code that i use to open

import pickle
tilemap = pickle.load('data/tilemap2.txt')
print (tilemap)
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Gribouillis
0

Crash python course:

AttributeError: 'str' object has no attribute 'readline'

.... hmmm readline ? ding dong! ==> python was expecting a file.
It found a string ahah! I forgot to open a file :)

Edited by Gribouillis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.