Note that there are some explanatory texts on larger screens.

plurals
  1. POUnboundLocalError after 67th successful function call in single script
    primarykey
    data
    text
    <p>I'm extracting large amounts of data from excel sheets, to be written to another excel file. Script looks something like this:</p> <pre><code>def foo(file): open file write specific cells to new workbook in memory based on some logic foo(file001) foo(file002) . . . foo(file110) save output file </code></pre> <p>The functionality of foo() is not an issue, it runs fine. However, the script threw an <code>UnboundLocalError: local variable referenced before assignment</code> after loading file 77 (which would be the 67th time the function had been called in that script).</p> <p>The excel files have identical layouts, and the data being pulled only varies by the value. Barring any script error (of which I am virtually sure have been avoided), are there any logic or overflow reasons why an error like this would appear only after calling the same function repeatedly?</p> <p>I'm currently re-running the script to see if the error repeats, but it will take a few hours to get to the same point. Will update if different outcome.</p> <p>Using Python3.3 with openpyxl-1.6.2 and .xlsx files on WinXP. (to myself: script v1.6.00)</p> <hr> <p><strong>Edit</strong></p> <p>Looking again at the source excel files, I found that the file throwing the error had been artificially shortened due to a problem with exporting the original data. (Notes indicated that the data collection computer crashed when writing the data.)</p> <p>Part of the foo() logic included storing the row number of a specific cell for later manipulation. However, in this shortened file, that row did not exist, thus creating an <code>UnboundLocalError</code> when the stored row number was called later.</p> <p>For my purposes, the data can be discarded, which solves the problem.</p> <hr> <p><strong>Summary</strong> </p> <p>If you're sure your code is fine, take a look at your source files for any potential problems.</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. 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