Repository navigation
Conversation
|
Please be more specific. Show the actual args you passed for both filename and file_contents, and show the outcomes you experience before and after your change. |
|
@sjmachin Apologies, completely missed this in github noise! Just encountered again :) I use with open('myfile.xls', 'rb') as f:
f.read()
# next read() will return empty str
open_workbook(filename=None, file_contents=f.read())Result: This logic isn't strong enough IMHO because 1) it doesn't discriminate between if file_contents:
# use the file_contents
else:
# use the filenameI would favour this: if file_contents is not None:
if not len(file_contents):
raise ValueError("file_contents is empty")
# use file_contents
elif filename is not None:
# use filename
else:
raise RuntimeError("Require one of file_contents or filename")Happy to regenerate the pull request if required? |
|
I think the current change in d8d3d01 is fine, just needs a unit test, howevr, if we want to be more informative: "if not len(file_contents):" is horrible, that should just be "if not filecontents". I like the 'else' clause :-) But yes, a pull request would be great, please include tests in the unit test suite. A ShouldRaise would be the way to go... |
|
No followup. |
With a default argument ie file_contents = None
Checking if file_contents has been provided using:
if file_contents:
... returns False for an empty file. This leads to very tedious debugging if your file happens to be empty!