Problem in Using re.subn()
Joseph C. Kopec
kopecjc at worldnet.att.net
Fri Feb 18 07:34:45 EST 2000
I was working through an example in Preston Lander's "Writing CGI
Scripts in Python" on DevShed
(http://www.devshed.com/Server_Side/Python/CGI/) -- an excellent
article, which I highly recommend -- and kept getting an error message
when attempting to run a script set forth therein containing re.subn().
Basically, the re.subn() call looks like this:
def Display(Content):
TemplateHandle = open(TemplateFile, "r") # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle.read()
TemplateHandle.close() # close the file
# this defines an exception string in case our
# template file is messed up
BadTemplateException = "There was a problem with the HTML template."
SubResult = re.subn('<!-- *** INSERT CONTENT HERE *** -->', Content,
TemplateInput)
if SubResult[1] == 0:
raise BadTemplateException
print "Content-Type: text/html\n\n"
print SubResult[0]
Which gives a Trackback of:
Traceback (innermost last):
File "/usr/local/apache/cgi-bin/process.py", line 100, in ?
DisplayForm()
File "/usr/local/apache/cgi-bin/process.py", line 38, in DisplayForm
Display(FormInput)
File "/usr/local/apache/cgi-bin/process.py", line 23, in Display
SubResult = re.subn('<!-- *** INSERT CONTENT HERE *** -->', Content,
TemplateInput)
File "/var/tmp/python-root/usr/lib/python1.5/re.py", line 52, in subn
pattern = _cachecompile(pattern)
File "/var/tmp/python-root/usr/lib/python1.5/re.py", line 33, in
_cachecompile
value = compile(pattern, flags)
File "/var/tmp/python-root/usr/lib/python1.5/re.py", line 79, in
compile
code=pcre_compile(pattern, flags, groupindex)
pcre.error: ('nothing to repeat', 6)
I know my Content and TemplateInput values are good strings. Does
anyone have any guess what is going on? Any suggestions would be much
appreciated.
More information about the Python-list
mailing list