R
Robert Oschler
Hello,
I am a Python newbie (by experience, not chronologically ), so if any of
this doesn't make sense my apologies in advance.
I am reading the chapter in The Python Cookbook on databases and the MySQLdb
module. In it they show an example of a recipe that lets you access fields
in a MySQL row by name rather than by column number. For example, given a
MySQL row object from a fetchone() call:
employee_name = sqlrow[field_dict['empname']]
To make the syntax easier and clearer, I would like to create a Python class
instance that would allow me to access the fields in the MySQL row as
attributes of a class created dynamically from the row structure. For
example:
employee_name = ez_sqlrow.empname
What would be the best way to create such a class or class instance? Any
code examples you have would be welcome.
Thanks
I am a Python newbie (by experience, not chronologically ), so if any of
this doesn't make sense my apologies in advance.
I am reading the chapter in The Python Cookbook on databases and the MySQLdb
module. In it they show an example of a recipe that lets you access fields
in a MySQL row by name rather than by column number. For example, given a
MySQL row object from a fetchone() call:
employee_name = sqlrow[field_dict['empname']]
To make the syntax easier and clearer, I would like to create a Python class
instance that would allow me to access the fields in the MySQL row as
attributes of a class created dynamically from the row structure. For
example:
employee_name = ez_sqlrow.empname
What would be the best way to create such a class or class instance? Any
code examples you have would be welcome.
Thanks