scanning through page and replacing all instances of 00:00:00.00

Tim Chase python.list at tim.thechases.com
Mon Apr 17 19:27:06 EDT 2006


> 		for col in range(0, numcols):
> 			print "<td>", record[col], "</td>"

This is the point at which you want to intercept the column 
data and make your change:

print "<td>", str(record[col]).replace("00:00:00.0", ""), "</td"

If it's possible/plausible that other fields might have such 
a value reasonably, then you'd want to do a check, something 
like


THEDATECOL = 42
for col in range(0, numcols):
	foo = record[col]
	if col == THEDATECOL:
		foo = foo.replace("00:00:00.00", "")
	print "<td>%s</td>" % foo

or alternatively

DATECOLUMNS = [3, 14]
for col in range(0, numcols):
	foo = record[col]
	if col in DATECOLUMNS:
		foo = foo.replace("00:00:00.00", "")
	print "<td>%s</td>" % foo

I don't know off the top of my head if your MySQL cursor 
object supports metadata...something like the following 
pseudocode:

for col in range(0, numcols):
	foo = record[col]
	if cursor.fieldtypes[col] == MYSQL_DATE:
		foo = foo.replace("00:00:00.00", "")
	print "<td>%s</td>" % foo

Adjust accordingly.

-tkc








More information about the Python-list mailing list