|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
RE and html and MySQL need help
I've deduced from the error messages it has too do something with thedate 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() 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 |
|
#2
|
|||
|
|||
|
more stuff
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 ps make the the text box bigger i dont know how to format it so it appears nicely ![]() |
|
#3
|
||||
|
||||
|
Hey Ark, normally to keep indentation in your code you want to put a [ CODE ][ /CODE ] tag around it (no spaces). Because this one is so big i think it would be best just to attache the file
![]() Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > RE and html and MySQL need help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|