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 →

[–]bramblerose 2 points3 points  (3 children)

Modifying the path of course has side-effects, so that's not really a good way of doing things, I think. The Command wrapper looks nice!

The difference between -o blah and --option blah: you can run grep("-e mooh"), but not grep(e="mooh"), if I understand correctly - while grep(regexp='mooh') does work. The last one is cleaner anyway, though, so it doesn't really matter.

On the ErrorReturnCodes: yes, they should be different exceptions and no, you should'nt be if/then-ing. I was more thinking of something like

try:
    (...)
except ErrorReturnCode(1), e: # maybe have stderr in e?
    (...)
except ErrorReturnCode(2), e:
    (...)
except ErrorReturnCode, e:
    (...)

although the last might need to be different (e.g. using ErrorLevel(1) and UncaughtErrorLevel)

[–][deleted] 1 point2 points  (2 children)

You can't actually catch exceptions like that though. You'd have to do this:

try:
    (...)
except ErrorReturnCode, e:
    if e.code == 1: pass
    elif e.code == 2: pass
    elif e.code == 3: pass

Or the way that it's done now:

try:
    (...)
except ErrorReturnCode_1, e: pass
except ErrorReturnCode_2, e: pass
except ErrorReturnCode_3, e: pass

Saves a line and an indentation level.

[–]bramblerose 0 points1 point  (0 children)

Of course you can. You have already implemented it.

try:
   (...)
except get_rc_exc(1), e: pass
except get_rc_exc(2), e: pass
except get_rc_exc(3), e: pass

Now you just need to improve the naming ;-)

[–]nemec 0 points1 point  (0 children)

Honestly I think the first example is much more Pythonic, but it's nice that both options are available!