[Tutor] Weird error message

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Nov 6 21:23:01 EST 2003



On Thu, 6 Nov 2003, Conrad Koziol wrote:

> Hey Danny thanks for the tips but it still doesn't work. :(
> I've deduced from the error messages it has too do something with the
> date time object of x[1].


Hi Conrad,


In the statements:

###
    posts = re.sub(content1, post[0], posts)
    posts = re.sub(content2, post[1], posts)
    posts = re.sub(content3, post[2], posts)
    posts = re.sub(content4, post[3], posts)
###

the code works only if post[0], post[1], post[2] and post[3] represent
non-NULL strings: re.sub only deals with strings, and will choke if given
anything else.  (I'm lying: re.sub() can take in a function as a second
argument, but let's ignore that for the moment.  *grin*)


Since post[1] is a DateType object, the code needs to do something before
passing it to re.sub().  Something like:

###
    posts = re.sub(content1, str(post[0]), posts)
    posts = re.sub(content2, str(post[1]), posts)
    posts = re.sub(content3, str(post[2]), posts)
    posts = re.sub(content4, str(post[3]), posts)
###

should behave a little more reliably.




More information about the Tutor mailing list