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

Fredrik Lundh fredrik at pythonware.com
Tue Apr 18 03:43:15 EDT 2006


skip at pobox.com wrote:
>
>    Kun> assuming that my date column is 2, how would i parse out the date?
>
> No parsing required.  Just get its date:
>
>    d = record[2].date()
>
> The str() of a datetime.date object is a string in YYYY-MM-DD form.

or, in other words, change:

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

to

    # convert to list, so we can replace columns, if needed
    record = list(record)

    # fix the date column
    record[2] = record[2].date()
    # add other fixups here

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

the last two lines are of course better written as

    for col in record:
        print "<td>", col, "</td>"

</F> 






More information about the Python-list mailing list