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

[pygame] off by one error, line 55 in arraydemo.py



I'm writing because I found what looks like an off by one error in arraydemo.py, in the examples directory (it's in the pygame-1.7.1release.zip and repeated in the tutorial online http://www.pygame.org/docs/tut/surfarray/SurfarrayIntro.html).  I found it while trying to figure out slicing (I'm fairly new to python, and some of the slicing syntax still isn't intuitive to me). There's a slice where an array gets reversed, only it looks like the new array loses data because of the slice call. It's not a big deal and it doesn't break the program. I just thought that as a learning device it makes sense to make sure the code is clean.
 
Line 55 in arraydemo.py
   flipped = imgarray[:,-1:0:-1]
 

This should be:
   flipped = imgarray[:,-1::-1]
 

That is if the intention is for the entire surface to be copied in reverse form and not lose the last(first) element.
 
This is the data I tested my slicing on for your reference.
Python 2.3.5, on a Gentoo Linux box
>>>a = ['a','b','c']
>>>a
['a', 'b', 'c']
>>>a[-1:0:-1]
['c', 'b']
>>>a[-1::-1]
['c', 'b', 'a']
 

Thanks,
Miles