Seekable files

Marko Rauhamaa marko at pacujo.net
Tue Mar 15 07:16:37 EDT 2016


Jon Ribbens <jon+usenet at unequivocal.co.uk>:

> I'd just do something like:
>
>   try:
>       fileobj.seek(where-i-want-to-seek-to)
>   except (AttributeError, EnvironmentError):
>       # file is not seekable

Unlike Java, Python does not declare syntactically which exceptions the
caller should expect. Unfortunately, the library documentation is not
clear on it, either. So it is often a bit difficult to write proper
try-except logic around a function.

Having to specify the possible exceptions in Java is very painful and
has complicated the introduction of closures to Java quite a bit. I
think it points to a big practical problem in the whole exception
paradigm. Makes you wonder if the old error code mechanism would have
been better, after all. ("Why does Go not have exceptions?" <URL:
https://golang.org/doc/faq>.)


Marko



More information about the Python-list mailing list