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

R

richard.hsu

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 ?

thank you in advance for educating me.
 
F

Fredrik Lundh

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top