[Tutor] Weird error message

Conrad Koziol arkamir at softhome.net
Thu Nov 6 18:33:19 EST 2003


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].
I was hoping you guys could supply me with an answer.

This is the code in question:
	
	
	
	
import MySQLdb
import re
import compare
import numberofpages
import display
import time 
	
db = MySQLdb.connect(host='localhost', user='conrad',
passwd='mysqlinsecret', db='cgi')

cursor = db.cursor()
#import retrieveposts
#retrieveposts.retrieve_posts('general', 'Hello, World', 20)

def retrieve_posts(forum, thread, end_post):
	giventemplate = 'posttemplate'
	inputtemplate = open(giventemplate, 'r')
	posttemplate = inputtemplate.read()
	inputtemplate.close()
	start_post = end_post - 20
	cursor.execute('''select names, dates, subjects, posts, positions from
%s where threads = \'%s\' and positions > \'%s\' and positions <
\'%s\'''' % (forum, thread, start_post, end_post))
	postsinfo = cursor.fetchall()
	
	postsinfo = list(postsinfo)
	postsinfo.sort(compare.compare)
	posts = posttemplate
	subsitutes = ['NAME', 'DATE', 'SUBJECT', 'POST']
	list_of_posts = []
	
	
	# 1111111 expression = '<!--INSERT %s HERE-->' 
	
	
	content1 = re.escape('<!--INSERT NAME HERE-->')
	content2 = re.escape('<!--INSERT DATE HERE-->')
	content3 = re.escape('<!--INSERT SUBJECT HERE-->')
	content4 = re.escape('<!--INSERT POST HERE-->')
	
	for post in postsinfo:
		#change it from a datetime object
		repr(post[1])
		for value in range(4):
			# 1111111 posts = re.sub((expression, post[value], posts) %
subsitutes[value])
			posts = re.sub(content1, post[0], posts)
			#this is where the error occurs
			posts = re.sub(content2, post[1], posts)
			posts = re.sub(content3, post[2], posts)
			posts = re.sub(content4, post[3], posts)
			print posts
			list_of_posts.append(posts)
			posts = posttemplate
			
This is posttemplate:
			
<div class="postholder">
	<div class="name">
					<br>
					<!--INSERT NAME HERE-->
					<br>
					<p>Posted on: <!--INSERT DATE HERE-->  </p>
	</div>
	<div class="subject">
	
		<!--INSERT SUBJECT HERE-->	 
	</div>
	<div class="post"> 
			<br>	
			<br>
			
			<!--INSERT POST HERE-->
			<br>
			<br>
			<br>
			<br>
			<br>
			<br>	
	</div>
</div>

This is the error message:


>>> import retrieveposts
>>> retrieveposts.retrieve_posts('general', 'Hello, World', 20)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "retrieveposts.py", line 45, in retrieve_posts
    posts = re.sub(content2, post[1], posts)
  File "/usr/lib/python2.2/sre.py", line 143, in sub
    return _compile(pattern, 0).sub(repl, string, count)
  File "/usr/lib/python2.2/sre.py", line 257, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/lib/python2.2/sre.py", line 242, in _compile_repl
    p = sre_parse.parse_template(repl, pattern)
  File "/usr/lib/python2.2/sre_parse.py", line 644, in parse_template
    s = Tokenizer(source)
  File "/usr/lib/python2.2/sre_parse.py", line 186, in __init__
    self.__next()
  File "/usr/lib/python2.2/sre_parse.py", line 188, in __next
    if self.index >= len(self.string):
TypeError: len() of unsized object
>>>

Thanks for the help
		Conrad




More information about the Tutor mailing list