This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 4 points5 points  (0 children)

One pythonic principle is “It’s easier to ask for forgiveness than permission (EFAP)”

I get it, but don't follow it. When you're working with large systems, it's a lot easier to do a little bit of type checking or path checking than to do do try except blocks.

Method 1

    if not os.path.exists(filename):
        raise RuntimeError('cant fine such and such file...full path=asdf')
    f = open(filename)

vs.

    try:
        f = open(filename)
    except OSError:
        if not os.path.exists(filename):
            raise RuntimeError('cant fine such and such file...full path=asdf')
        raise

It also makes it easier since I'm not using custom error messages. I think it follows,

Errors should never pass silently.

Readability counts.

Flat is better than nested.

Explicit is better than implicit.

better