471,092 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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

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.

Apr 6 '06 #1
1 886
ri*********@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>

Apr 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Nicolas Evrard | last post: by
4 posts views Thread by John Cho | last post: by
4 posts views Thread by Steven | last post: by
3 posts views Thread by Bryan Olson | last post: by
17 posts views Thread by Jon Slaughter | last post: by
11 posts views Thread by John Salerno | last post: by
10 posts views Thread by Ratnesh Raval | last post: by
3 posts views Thread by pb | last post: by
1 post views Thread by subramanian100in | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.