Re: How to make this simple code look better

2015-10-27 Thread Ben Finney
Dennis Lee Bieber writes: > Actually, if 0 is success, and you are testing for a failure, it > should probably just be > > if ret: > #do error That obscures the intent; there is nothing about “is ‘ret’ false?” that tells me what the meaning of that test is. It happens

Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
On Tue, Oct 27, 2015 at 5:38 PM, Tim Chase wrote: > It reduces the redundant code and also brings all of the commands > together in one place to see the expected steps. Thanks your suggested code looks nice , I easily knocked off half the lines of my code :) -- https://mail.python.org/mailman/l

Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
> According to the format strings, 'ret' is a number. If that's the case, > it's not a string, so ret != "" will always be true. > > Why are you wrapping the command string literals in (...)? That's not > necessary. > > You're doing the same thing with each of the command strings, so why > not put

Re: How to make this simple code look better

2015-10-27 Thread Tim Chase
On 2015-10-27 17:24, Ganesh Pal wrote: > from myPopen import run > > def configure_network(): > """ > Prepare network for test > """ > try: > cmd = ("netadm enable -p ncp DefaultFixed") > out, err, ret = run(cmd, timeout=60) > if ret != "": > log

Re: How to make this simple code look better

2015-10-27 Thread MRAB
On 2015-10-27 11:54, Ganesh Pal wrote: from myPopen import run def configure_network(): """ Prepare network for test """ try: cmd = ("netadm enable -p ncp DefaultFixed") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("

How to make this simple code look better

2015-10-27 Thread Ganesh Pal
from myPopen import run def configure_network(): """ Prepare network for test """ try: cmd = ("netadm enable -p ncp DefaultFixed") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))