question on storing dates in a tuple
rhodri at wildebst.demon.co.uk
Thu Feb 11 02:36:11 CET 2010
On Thu, 11 Feb 2010 01:17:17 -0000, m_ahlenius <ahleniusm at gmail.com> wrote:
> 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.
> 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
> 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:
rhodri at 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)
>>> 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
More information about the Python-list