[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] stupidity, and a lesson learned



Hi everybody,

I just got hit by the silliest, stupidest error on my part and I
decided to share it, since it was kinda funny after the fact and so
that no one else would make my mistake.

This was the data I was trying to parse (a map format I was making):

mapname=DeathMap
mapauthor=pumaninja
mapdate=12172006
mapversion=0.0.1
mapwidth=10
mapheight=5

And this was the code I was using to get the info out of the file:

elif info.find("mapauthor=") == 0:  # 0 means that the string has been found
               temp = ""
               temp = info.strip("mapauthor=")
               map_author.append(temp)

I was thinking that the .strip() simply took out the specified
absolute phrase. I was wrong. The .strip() looks for all the
characters specified and takes them out. For the other tags, this did
not get me since none of the other names matched any where close to
data type or the combination of letters. Only for the author part
because I had put in pumaninja which if you see has p, u, m, a
contained in mapauthor.

Ah, well, at least this didnt come back and get me way after the fact.
Although, this code was based on a part of a game I had already
written, that one missed the bullet because the info was numbers and
not characters.

Moral of the story : Clearly read the docs, and test the function with
various data types.

Happy coding,
-spot