question on storing dates in a tuple

M

m_ahlenius

Hi,

I have a weird question about tuples. I am getting some dates from a
mysql db, using the mysqldb interface. I am doing a standard query
with several of the fields are "datetime" format in mysql.
When I retrieve and print them in python, they look fine.

eg.
storeddate = 2010-02-07 12:03:41

But when I append these dates into a string to write to an ascii log
file, they come out as:

datetime.datetime(2010, 2, 7, 12, 03, 41) (or something along those
lines).

It appears that I am dealing with some sort of date object here. So
I am just trying to understand what's going on, and whats the best
work with such objects.

thanks

'mark
 
C

Chris Rebert

Hi,

I have a weird question about tuples.  I am getting some dates from a
mysql db, using the mysqldb interface.  I am doing a standard query
with several of the fields are "datetime" format in mysql.
When I retrieve and print them in python, they look fine.

eg.
storeddate = 2010-02-07 12:03:41

But when I append these dates  into a string to write to an ascii  log
file, they come out as:

datetime.datetime(2010, 2, 7, 12, 03, 41)    (or something along those
lines).

It appears that I am dealing with some sort of date object here.   So
I am just trying to understand what's going on, and whats the best
work with such objects.
http://docs.python.org/library/datetime.html#datetime.datetime
(datetime.datetime(2010, 2, 10, 17, 22, 12, 459277),)

tuples use repr() on their elements when they're converted to strings,
and repr() on datetime-s uses the constructor notation as opposed to
the more normal notation used by str(). Same sort of thing happens
with strings; note the presence/lack of quotes:
('aa',)

Cheers,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top