Made a quick script on my windows pc to query an api and write to a spreadsheet. The issue is that the person running this will be on mac, so Im trying to port it to mac os but I believe I've run into a file path error? Everything looks right though so I'm confused. Thank you in advance for any help. I'm very unfamiliar with mac.
The excel module I'm using isnt able to open the workbook I have. It's openpyxl.
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
save =tkFileDialog.asksaveasfilename(defaultextension=".xlsx",initialfile=file_path)
main(file_path,save)
def main(load,save):
try:
wb = load_workbook(load)
except:
print load,save
return
I expect the workbook to be opened but instead it's printing the file path and ending main().
Here are the file paths it's printing out:
/Users/edwin/Downloads/190117 CA Device Roster.xlsx /Users/edwin/Downloads/:Users:edwin:Downloads:test.xlsx
答案 0 :(得分:0)
except:
. Why are you expclicitly catching all exceptions and then not exposing them to the user? Ignoring exceptions doesn't make the problem go away - it just stops you from seeing it. Which means your code doesn't work and you don't know why.
If you need additional debugging in your except
, it's fine, just raise the original exception afterwards:
except Exception as e:
print(load,save)
raise e
Anything other than exposing the exception you got is going to hide your errors, leaving you with no option but to guess what's going wrong. Good engineers don't guess - they increase logging.