Re: Why ELIF?

2009-10-12 Thread Esmail
TerryP wrote: Somehow I doubt that Look up X in dictionary D could ever be more efficient (in terms of space and time, at least) then Check if X is equal to Y. It's not about what you get in runtime but what you get in monkey time. Most expressions that would make someone reach for a C-like

Why ELIF?

2009-10-11 Thread metal
I wonder the reason for ELIF. it's not aligned with IF, make code ugly IMHO OR maybe better? if foo == bar: ... or foo == baz: ... or foo == bra: ... else: ... -- http://mail.python.org/mailman/listinfo/python-list

Re: Why ELIF?

2009-10-11 Thread Erik Max Francis
metal wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly IMHO OR maybe better? if foo == bar: ... or foo == baz: ... or foo == bra: ... else: ... Because that's uglier. `or` means something completely unrelated in expressions.

Re: Why ELIF?

2009-10-11 Thread Steven D'Aprano
On Sat, 10 Oct 2009 23:47:38 -0700, metal wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly IMHO OR maybe better? if foo == bar: ... or foo == baz: ... or foo == bra: ... else: ... `or` has another meaning in Python, and many

Re: Why ELIF?

2009-10-11 Thread Grant Edwards
On 2009-10-11, metal metal...@gmail.com wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly It most certainly is aligned with IF: if cond1: do this elif cond2: do that else: do the other The if elif and else are all aligned in all of the code

Re: Why ELIF?

2009-10-11 Thread TerryP
On Oct 11, 7:07 am, Erik Max Francis m...@alcyone.com wrote: Because that's uglier.  `or` means something completely unrelated in expressions.  Variations of `else if` in `if ... else if ...` chains is routine in computer languages.  Choosing a deliberately different syntax just for the sake

Re: Why ELIF?

2009-10-11 Thread Esmail
Steven D'Aprano wrote: By the way, if you're testing a single name against a series of alternatives, it is often better to look up the value in a dictionary: table = {bar: 23, baz: 42, boop: 73, beep: 124} value = table[foo] instead of: if foo == bar: value = 23 elif foo == baz:

Re: Why ELIF?

2009-10-11 Thread MRAB
Grant Edwards wrote: On 2009-10-11, metal metal...@gmail.com wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly It most certainly is aligned with IF: if cond1: do this elif cond2: do that else: do the other The if elif and else are all

Re: Why ELIF?

2009-10-11 Thread TerryP
On Oct 11, 3:42 pm, Esmail ebo...@hotmail.com wrote: cool .. I hadn't seen that. Not working quite at the 'pythonic' level yet I am not sure I think it's more readable that the if statement. Also, curious if the dictionary approach is more efficient. Somehow I doubt that Look up X in

Re: Why ELIF?

2009-10-11 Thread Simon Forman
On Sun, Oct 11, 2009 at 2:15 PM, TerryP bigboss1...@gmail.com wrote: On Oct 11, 3:42 pm, Esmail ebo...@hotmail.com wrote: cool .. I hadn't seen that. Not working quite at the 'pythonic' level yet I am not sure I think it's more readable that the if statement. Also, curious if the dictionary

Re: Why ELIF?

2009-10-11 Thread Mick Krippendorf
TerryP schrieb: Note: let Commands be a dictionary, such that { ham : ..., spam : ..., eggs : ... }. args = re.split('\s', line) cmd = args.pop(0) if cmd in Commands: Commands[cmd](args) else: raise SyntaxWarning(Syntax error in above program) [...] I might take

Re: Why ELIF?

2009-10-11 Thread MRAB
Simon Forman wrote: [snip] I'll often do that this way: args = re.split('\s', line) This has the same result, but is shorter and quicker: args = line.split() -- http://mail.python.org/mailman/listinfo/python-list

Re: Why ELIF?

2009-10-11 Thread Steven D'Aprano
On Sun, 11 Oct 2009 11:15:06 -0700, TerryP wrote: On Oct 11, 3:42 pm, Esmail ebo...@hotmail.com wrote: cool .. I hadn't seen that. Not working quite at the 'pythonic' level yet I am not sure I think it's more readable that the if statement. Also, curious if the dictionary approach is more

Re: Why ELIF?

2009-10-11 Thread Carl Banks
On Oct 11, 7:10 am, Grant Edwards inva...@invalid.invalid wrote: On 2009-10-11, metal metal...@gmail.com wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly It most certainly is aligned with IF:   if cond1:       do this   elif cond2:       do that   else:    

Re: Why ELIF?

2009-10-11 Thread Mensanator
On Oct 11, 5:05�pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 11, 7:10�am, Grant Edwards inva...@invalid.invalid wrote: On 2009-10-11, metal metal...@gmail.com wrote: I wonder the reason for ELIF. it's not aligned with IF, make code ugly It most certainly is aligned with IF:

Re: Why ELIF?

2009-10-11 Thread Carl Banks
On Oct 11, 4:12 pm, Mensanator mensana...@aol.com wrote: On Oct 11, 5:05 pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 11, 7:10 am, Grant Edwards inva...@invalid.invalid wrote: On 2009-10-11, metal metal...@gmail.com wrote: I wonder the reason for ELIF. it's not aligned

Re: Why ELIF?

2009-10-11 Thread John Machin
MRAB python at mrabarnett.plus.com writes: Simon Forman wrote: [snip] I'll often do that this way: args = re.split('\s', line) This has the same result, but is shorter and quicker: args = line.split() HUH? Shorter and quicker, yes, but provides much better functionality;

Re: Why ELIF?

2009-10-11 Thread Mensanator
On Oct 11, 6:43�pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 11, 4:12�pm, Mensanator mensana...@aol.com wrote: On Oct 11, 5:05 pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 11, 7:10 am, Grant Edwards inva...@invalid.invalid wrote: On 2009-10-11, metal

Re: Why ELIF?

2009-10-11 Thread TerryP
On Oct 11, 9:43 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 11 Oct 2009 11:15:06 -0700, TerryP wrote: I might take flak here, for writing something like 'dict[key] (func_args)' instead of something more Pythonic, Looking up a first-class function in a dictionary