I'm programming a RPG game, so I have the function load_map
, with an XML map, I have to decode and decompress the layer. This is the code:
# Decodifica una cadena en base64 y luego la descomprime.
def decode(cadena):
# Decodificar.
cadena = base64.decodestring(cadena)
# Descomprimir.
copmressed_stream = StringIO.StringIO(cadena)
gzipper = gzip.GzipFile(fileobj=copmressed_stream)
cadena = gzipper.read()
# Convertir.
salida = []
for idx in xrange(0, len(cadena), 4):
val = ord(str(cadena[idx])) | (ord(str(cadena[idx + 1])) << 8) | \
(ord(str(cadena[idx + 2])) << 16) | (ord(str(cadena[idx + 3])) << 24)
salida.append(val)
return salida
The error is in cadena=gzipper.read()
. Why am I getting this error, and how can I fix it?
add exception catch such as try...except... will be good. you can make sure your test file-type is gzip by shell command as icktoofay. Certianly , command 'file test.gzip' will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.