Search code examples
pythondatabasedatahandler

How to get field names and records from a return object


I m trying to get field names and record values from a return database object. I have a datahandler.py file for query exection. when i hit a datahandler method(say for eg. GetEmployeeinfo(id)) from one of source file it return a object. I want to know how to get the field names and record vlues from the object which is returned by GetEmployeeinfo(id).

MyCode looks like this:

Employee.py

 class EmployeeForm(BrowserView)

 def getEmployee(self):
    handler=self.MyDBHandler()
    emp_info=handler.GetEmployeeinfo(id=1) // this return the object from a 
                                              GetEmployeeinfo(id)
    return emp_info

dbhandler.py

  class MyDBhandler():

  def GetEmployeeinfo(id,dic=0)
    //some select statement query goes here 
     return []
    // it return the object instance like "<My.Product.dbhandler.xxxx>"

I want to know how to get the field names and records from the return object in Employee.py file to return it to the render page.

thanks in advance.


Solution

    1. Read the docs for that class as long as you have one.
    2. print help(My.Product.dbhandler.xxxx) to see the help info on that class, or use print dir(My.Product.dbhandler.xxxx) to see the attributes and methods of that class.
    3. If you have some IDE(e.g. eclipse with pyDev) or enhanced shell/editor(e.g. iPython) with auto-completion, just type My.Product.dbhandler.xxxx.<TAB> to see the code completion.