Return multiple rows and use in another function in Python

Viewed 31

I am trying to return the result in one function and use the result in another function. But the function extract() returns only one record. Expectation is to return all the records from a table.

def extract(self):
    data = self.oracle_conn().execute('select * from employees').fetchall()
    for row in data:
        return row
1 Answers

You can use list comprehension to return a list of all records:

def extract(self):
    data = self.oracle_conn().execute('select * from employees').fetchall()
    return [row for row in data]
Related