Apr-02-2020, 08:12 AM
This part is useless:
they could disappear after the check. This is not
a protection against Exception like FileNotFoundError
or PermissionError.
Python has for everything Exceptions.
If you get for example a PermissionError and want to look up the inheritance:
existe_txt = os.path.exists(txt) existe_xls = os.path.exists(xls)The cause is, even if the files both are existing,
they could disappear after the check. This is not
a protection against Exception like FileNotFoundError
or PermissionError.
Python has for everything Exceptions.
def main(): try: data = pd.read_csv(txt, sep="|", header=None, encoding='ISO-8859-1', chunksize=big_file) writer = pd.ExcelWriter('output.xlsx') except (FileNotFoundError, PermissionError) as err: print(err) return for df in data: ... ... writer.save()You could catch more general Exception.
If you get for example a PermissionError and want to look up the inheritance:
PermissionError.mro()
Output:[PermissionError, OSError, Exception, BaseException, object]
This Exception could be catched by: PermissionError, OSError, Exception
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!