UnboundLocalError: local variable 'cell' referenced before assignment
I work with spreadsheets published by governments, and whatever software they are using commonly sets metadata such that calculate_dimension()
returns "A1:A1".
To work around this issue, I check if calculate_dimension()
returns "A1:A1", and if so I run calculate_dimension(force=True)
.
This is fine if the metadata is, in fact, incorrect. However, if the file is empty (which also sometimes happens), then the UnboundLocalError
occurs.
I know I can put a try/except around this code, but it seems like you could also just set cell = None
before the loop, and then assign self._max_row = cell.row if cell is not None else 0
.
Edited by James McKinney