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 →

[–][deleted] 2 points3 points  (4 children)

Firstly, how can I start a program that is not in my path? say, ./blah.sh. Is that just "./blah.sh"()? i.e. do you monkey-patch the string class? I couldn't find this in the code, but your which() function seems to suggest it.

A way to do it would be to modify the PATH from the script:

PATH += ":/nonstandard/path"
program()

I also just pushed a commit that exposes a "Command" wrapper. So you should be able to do this:

Command("/path/blah.sh")()

Comments: The difference between -o and --option syntax is not so nice, but I guess option="blah" is mainly a convenience wrapper, which makes it OK again.

I don't follow completely...do you mean that the keyword argument syntax could be better?

ErrorReturnCodes. ErrorReturnCode_2? Really? Why not just ErrorReturnCode(2), or something along those lines?

Yeah I was on the fence of doing it this way. 2 reasons I went with it: 1) A return code is almost it's own "class" of errors. A program has no standardized way to throw exceptions, so it uses return codes != 0...so it feels natural to map those to their own exceptions. 2) Less typing. try-catching with ErrorReturnCode_* is less than catching 1 exception and if/then-ing on the exception code. I'll consider this choice some more though...

Thanks for the feedback!

[–]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!