> 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'])