Prev: Employee motivation in the software industry
Next: Pickling an extension type subclasses problems
From: John Posner on 5 Feb 2010 13:26 On 2/5/2010 11:53 AM, Gerald Britton wrote: > Also, I'm contractually obligated to >> admonish you not to "top post". > > Contract? Joke. (I know it's hard to tell.) > >> >> At any rate, I proposed the 3-line format specifically because it separates >> the data values from the if-then-else machinery, making it easier (for me) >> to read. But there was considerable resistance to spending so much vertical >> space in the source code. > > Weird! It's three lines and the original was four lines was it not>? Yes, but most people (including you, right?) seemed to think that conditional expressions are best confined to a single line. I proposed my 3-line alternative for expressions that *cannot* reasonably be confined to a single line. -John
From: Steven D'Aprano on 5 Feb 2010 17:19 On Fri, 05 Feb 2010 16:52:19 +0100, mk wrote: > assert isinstance(cmd, basestring) or cmd is None, "cmd should be string > or None" Do not use assertions for input validation. That's not what they're for. assert is compiled away when you run your code with the -O switch, which means that the test may never be made at all. You should limit assertions for testing "this can never happen" situations, verifying pre- and post- conditions, checking the internal logic of your code, and similar. See also: http://nedbatchelder.com/text/assert.html -- Steven
From: Steven D'Aprano on 5 Feb 2010 17:21 On Fri, 05 Feb 2010 15:21:05 +0100, mk wrote: > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) Whichever one you like. The differences are insignificance, and essentially boil down to personal preference. -- Steven
From: keakon on 6 Feb 2010 04:33 self.cmd = cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd
First
|
Prev
|
Pages: 1 2 3 4 5 Prev: Employee motivation in the software industry Next: Pickling an extension type subclasses problems |