[issue21570] String being confused with datetime.datetime object.
New submission from Brandon: Observe the following code: import MySQLdb, MySQLdb.cursors, datetime ... mysqlCursor is a cursor object from a connection to database from the MySQLdb module ... mysqlCursor.execute(SELECT NOW()) timeRow = mysqlCursor.fetchall() currentDateTime = datetime.datetime.strptime(timeRow[0][NOW()], %Y-%m-%d %H:%M:%S) I get the following error: TypeError: must be string, not datetime.datetime HOWEVER, when I cast timeRow[0][NOW()] to a string like: str(timeRow[0][NOW()]) , it works fine. For whatever reason the Python interpreter seems to interpret the string from the row of the MySQLdb cursor result as a datetime.datetime object. I have no explanation for this, besides it looking like a date time in the format of -mm-dd HH:MM:SS. I have not tried this in Python 3.x, but the bug is in the latest compile of version 2.7.6 from the FTP distribution site. -- components: Interpreter Core messages: 219041 nosy: brandon priority: normal severity: normal status: open title: String being confused with datetime.datetime object. type: compile error versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21570 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: [issue21570] String being confused with datetime.datetime object.
On 24.05.2014 15:55, Brandon wrote: Observe the following code: import MySQLdb, MySQLdb.cursors, datetime ... mysqlCursor is a cursor object from a connection to database from the MySQLdb module ... mysqlCursor.execute(SELECT NOW()) timeRow = mysqlCursor.fetchall() currentDateTime = datetime.datetime.strptime(timeRow[0][NOW()], %Y-%m-%d %H:%M:%S) I get the following error: TypeError: must be string, not datetime.datetime HOWEVER, when I cast timeRow[0][NOW()] to a string like: str(timeRow[0][NOW()]) , it works fine. For whatever reason the Python interpreter seems to interpret the string from the row of the MySQLdb cursor result as a datetime.datetime object. I have no explanation for this, besides it looking like a date time in the format of -mm-dd HH:MM:SS. It's likely that MySQLdb returns the datetime value as Python datetime.datetime object, so not really surprising that you get a TypeError. -- Marc-Andre Lemburg eGenix.com ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21570] String being confused with datetime.datetime object.
Brandon added the comment: Type returned as datetime, I was not familiar with the MySQLdb code. Sorry for the bad report. -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21570 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue21570] String being confused with datetime.datetime object.
Changes by Brandon x...@codeslum.org: -- resolution: - not a bug ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21570 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com