[Tutor] Weird error message

Conrad Koziol arkamir at softhome.net
Tue Nov 4 18:43:36 EST 2003


Hey thanks for the tip Danny but it still doesnt work. This is the last
bit of the code

	posts = posttemplate
	subsitutes = ['NAME', 'DATE', 'SUBJECT', 'POST']
	list_of_posts = []
	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:
		for value in range(4):
			posts = re.sub(content1, post[1], posts)
			posts = re.sub(content2, post[2], posts)
			posts = re.sub(content3, post[3], posts)
			posts = re.sub(content4, post[4], posts)
			
			list_of_posts.append(posts)
			posts = posttemplate

I still get this error though:


Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "retrieveposts.py", line 44, in retrieve_posts
    posts = re.sub(content1, 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

This the the templatefile which posts equals:

<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>

When I use this code I also get the same error, Except this code is a
lot prettier so I'd prefer to use this :). Another problem with this
code is I cant get it to replace the %s in expression with the data. I
think 
it has to do with it not finding the regular expression. Any help is
greatly appreciated.

	posts = posttemplate
	subsitutes = ['NAME', 'DATE', 'SUBJECT', 'POST']
	list_of_posts = []
	expression = '<!--INSERT %s HERE-->' 
		
	for post in postsinfo:
		for value in range(4):
			
			posts = re.sub((expression, post[value], posts) % subsitutes[value])
			
			list_of_posts.append(posts)
			posts = posttemplate

Thanks a lot,

	Conrad Koziol




More information about the Tutor mailing list