slicing question: rawdata[j:j+1] == 'xx' #will this ever be true ??

Fredrik Lundh fredrik at pythonware.com
Thu Apr 6 01:27:20 EDT 2006


richard.hsu at gmail.com wrote:

> I am new to python language and most of my python programming has been
> done with IronPython.
>
> I was looking at the source of markupbase.py which is included with
> Python 2.4 and came across the following line of code:-
>
> if rawdata[j:j+1] == '--': #comment
>
> i was confused because based on my understanding of the slicing syntax,
> rawdata[j:j+1] will either yield a string with ONE character or an
> empty string, therefore this boolean comparison will always be False
> because we are checking if it will be equal to a string with 2
> characters!
>
> am I missing something here ?

nope.

it's a bug, and it's fixed in 2.5 alpha, so there's no need to report it.

</F>






More information about the Python-list mailing list