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

2006-04-05 Thread 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.

-- 
http://mail.python.org/mailman/listinfo/python-list


finish_endtag in sgmllib.py [Python 2.4]

2006-04-11 Thread Richard Hsu
code:-

   # Internal -- finish processing of end tag
def finish_endtag(self, tag):
if not tag:  # < i am confused about this
found = len(self.stack) - 1
if found < 0:
self.unknown_endtag(tag)  # < and this
return

I am a little confused as to what is intended by " if not tag: "
does it mean
if tag == None or tag == "":  # ?

tag here is suppose to be a string.

so the only way it will be True is when its either None or its "", then
we are essentially passing None or "" to self.unknown_endtag(tag) ??

thank you in advance.

Richard Hsu
hobbyist programmer.
Toronto, Canada.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finish_endtag in sgmllib.py [Python 2.4]

2006-04-11 Thread Richard Hsu
thank you Ben. not only did i learn something about my question, i
learnt the 'truth' :-)

-- 
http://mail.python.org/mailman/listinfo/python-list