Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Python methods can return only <strong>one</strong> result at a time.</p> <p>That one result <em>can</em> be a list of lists; just return a larger list, and <em>loop</em> over the result:</p> <pre><code>result = [] row2 = [] while curr_row &lt; numOfRows: curr_row += 1 row2 = [] row = worksheet.row(curr_row) for value2 in re.findall(r"'(.*?)'", str(row)): row2.append(value2) result.append(row2) return result </code></pre> <p>and:</p> <pre><code>for row in Classobject.collectInfoFromXLS(): print row </code></pre> <p>A more advanced technique would be to turn your method into a generator function, and yield the rows, one by one. You'd still loop over the method. To make the function a generator, use a <code>yield</code> expression; you can no longer use <code>return</code> with a value once you make it a generator:</p> <pre><code>def collectInfoFromXLS(): workbookPath = config.get('TestCaseFileURL','XLSpath') workbook = xlrd.open_workbook(workbookPath) SheetPath = config.get('TesCaseSheetName','Sheet1') worksheet = workbook.sheet_by_name(SheetPath) numOfRows = worksheet.nrows - 1 curr_row = 0 row2 = [] while curr_row &lt; numOfRows: curr_row += 1 row2 = [] row = worksheet.row(curr_row) for value2 in re.findall(r"'(.*?)'", str(row)): row2.append(value2) yield row2 </code></pre> <p>You <em>still</em> have to loop over the output:</p> <pre><code>for row in Classobject.collectInfoFromXLS(): print row </code></pre> <p>only now <code>Classobject.collectInfoFromXLS()</code> returns a generator object instead of a list, and you can loop over that object only once.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload