On Thu, 11 Feb 2010 01:17:17 -0000, m_ahlenius <ahleni...@gmail.com> wrote:

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.

You're getting Python datetime objects:

rho...@gnudebst:~$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import datetime
now = datetime.datetime.today()
print str(now)
2010-02-11 01:30:03.749223
print repr(now)
datetime.datetime(2010, 2, 11, 1, 30, 3, 749223)


See http://docs.python.org/library/datetime.html#datetime-objects for details of what you can do with them. In your case, you probably just want to use "str()" to explicitly convert the object into a string.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to