Using Python 3.7.3 and mysql-connector 8.0.18, my SELECT result looks like:
[['2019-001', datetime.date(2019, 3, 11), 'Services']]
I would like the result to look like this:
[['2019-001', '11/03/2019', 'Services']]
Code snippet:
...
table = 'Customer'
select = "SELECT * FROM %s"
cursor.execute(select % table)
for row in cursor:
append_list = list(row)
import_list.append(append_list)
print(import_list) #import_list is actually a list of lists
...
I can't modify the SELECT statement (using ... DATE_FORMAT(Date, '%d/%m/%Y') ) as I don't know when/if a DATE field will be encountered, or the name of the field as I'm iterating over an unknown number of tables in the MySQL database.
The investigation I've done indicates a couple of possibilities (as far as I know):
- Iterating over import_list, and do some sort of datetime formating like:
datetime.date(2011, 1, 3).strftime("%d-%m-%Y")
This doesn't seem very elegant but if that's what I have to do, I need to figure out how to do that.
- I've seen reference to creating some sort of mysql.connector.conversion.MySQLConverter class. I don't know how to do that either, but I can investigate that further if this is the best way to go. This seems like a good way of doing things as it's done in the code that builds the connector.
Or is there another Pythonic way of doing what I'm trying to accomplish?