Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103109 > unrolled thread
| Started by | tdsperth@gmail.com |
|---|---|
| First post | 2016-02-18 04:08 -0800 |
| Last post | 2016-02-18 22:06 -0500 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
pymysql question tdsperth@gmail.com - 2016-02-18 04:08 -0800
Re: pymysql question MRAB <python@mrabarnett.plus.com> - 2016-02-18 12:52 +0000
Re: pymysql question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-18 22:06 -0500
| From | tdsperth@gmail.com |
|---|---|
| Date | 2016-02-18 04:08 -0800 |
| Subject | pymysql question |
| Message-ID | <0b27ecb5-4a3e-46dc-a83c-5ce806f46051@googlegroups.com> |
Hi All
I have many mysql tables in a conversion I am doing - the table field names are a mixture of lower case and upper case - do I have to covert all to one case to over come Python not finding the field.
rows ocur.fetchall()
for row in rows:
print(row['newname'])
#which fails because it is upper case in the table
Cheers
Colin
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2016-02-18 12:52 +0000 |
| Message-ID | <mailman.247.1455799968.22075.python-list@python.org> |
| In reply to | #103109 |
On 2016-02-18 12:08, tdsperth@gmail.com wrote: > Hi All > > I have many mysql tables in a conversion I am doing - the table field names are a mixture of lower case and upper case - do I have to covert all to one case to over come Python not finding the field. > > rows ocur.fetchall() > for row in rows: > print(row['newname']) > #which fails because it is upper case in the table > According to this: MySQL query to get column names? http://stackoverflow.com/questions/4165195/mysql-query-to-get-column-names it's possible to get the column names. You could then build a dict to map a lowercase column name to an actual column name.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2016-02-18 22:06 -0500 |
| Message-ID | <mailman.33.1455851173.2289.python-list@python.org> |
| In reply to | #103109 |
On Thu, 18 Feb 2016 12:52:32 +0000, MRAB <python@mrabarnett.plus.com>
declaimed the following:
>On 2016-02-18 12:08, tdsperth@gmail.com wrote:
>> Hi All
>>
>> I have many mysql tables in a conversion I am doing - the table field names are a mixture of lower case and upper case - do I have to covert all to one case to over come Python not finding the field.
>>
>> rows ocur.fetchall()
>> for row in rows:
>> print(row['newname'])
>> #which fails because it is upper case in the table
>>
>According to this:
>
>MySQL query to get column names?
>http://stackoverflow.com/questions/4165195/mysql-query-to-get-column-names
>
>it's possible to get the column names.
>
>You could then build a dict to map a lowercase column name to an actual
>column name.
Uhm... If pymysql is db-api compliant, you shouldn't need a query just
for the names... Any cursor that returns results has a description of the
fields in that result...
https://www.python.org/dev/peps/pep-0249/#cursor-attributes
One could build the mapping from the cursor.description attribute.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web