Struggling to convert a mysql datetime object to a python string of a different format

Νίκος nikos.the.gr33k at gmail.com
Thu Aug 5 17:01:28 EDT 2010


>On 5 Αύγ, 22:09, Tim Chase <python.l... at tim.thechases.com> wrote:
> On 08/05/10 13:52, Νίκος wrote:
>
> > dataset = cursor.fetchall()
>
> > for row in dataset:
> >      print ( '''<tr>  ''' )

As i have it the returned 'dataset' is stored line per line to 'row'.

So,
'dataset' in here is a 'list of tuples' right?
and
'row' in here is a tuple form the above list of tuples right?

Am i understanding this correctly?!


> Well, depending on whether "row" is a tuple or a list, you can do
> either

It was a tuple. But it migth as well be a list too?!?!

Could 'dataset' be a 'list of lists' as well?

How one would know in which way the returned mysql data is saved in?

> Though I think I'd make it a bit clearer by naming the fields:
>
>    for host, hits, dt in dataset:
>      print ("<tr>")
>      for item in (host, hits, dt.strftime(...)):
>        print ("<td>%s</td>" % item)
>      print ("</tr>")

Cool! I myself like this solution best over the all working other!
very nice approach thank you very much! Is what i anted and couldn't
write myself!

But please tell me if in my example 'row' was a tuple, what kind of
objects is 'host', 'hits', 'dt' here and how do they sore the data?

Thanks again for the cool examples!




More information about the Python-list mailing list