pymssql

sum abiut suabiut at gmail.com
Sun Sep 11 17:40:55 EDT 2016


Thanks heaps for your comments, manage to get it work using the as_dict`
parameter of the `cursor` object,

cus=conn.cursor(as_dict=True)
cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud")
for row in cus:
    print(row['budget_code'],row['budget_description'],row['rate_type'])


cheers,


On Sat, Sep 10, 2016 at 3:22 PM, Miki Tebeka <miki.tebeka at gmail.com> wrote:

> > for row in cus:
> >            print(row.budget_code)
> >
> >
> > NameError: name 'budget_code' is not defined
> You'll need to use a DictCursor to be able to access rows by name and not
> position (which IMO is the preferred way).
>
> cus = conn.cursor(pymysql.cursors.DictCursor)
> cus.execute("SELECT * FROM glbud ")
> for row in cus:
>     print(row['budget_code'])
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list