Re: auto increment
On 3/4/2011 12:07 AM, Chris Rebert wrote: On Thu, Mar 3, 2011 at 9:05 PM, Dan Strombergdrsali...@gmail.com wrote: On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebertc...@rebertia.com wrote: On Thu, Mar 3, 2011 at 8:41 PM, monkeys pawmon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. There's been discussion of adding i++ to python, but it was felt that the small number of saved keystrokes didn't justify the resulting bugs. I agree. Out of curiosity, what resulting bugs? Cheers, Chris no bugs, just less keystrokes than: i = i + 1 This is in interger form, BTW. -- http://mail.python.org/mailman/listinfo/python-list
Re: auto increment
Chris Rebert c...@rebertia.com wrote in message news:mailman.596.1299215244.1189.python-l...@python.org... On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg drsali...@gmail.com wrote: On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw mon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. There's been discussion of adding i++ to python, but it was felt that the small number of saved keystrokes didn't justify the resulting bugs. I agree. Out of curiosity, what resulting bugs? Probably things like i=(++i)+(--i), although more of being indeterminate than a bug. That assumes that ++i was intended for use in an expression, rather than just be a statement. -- Bartc -- http://mail.python.org/mailman/listinfo/python-list
Re: auto increment
On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw mon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. Regards, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: auto increment
On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw mon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. There's been discussion of adding i++ to python, but it was felt that the small number of saved keystrokes didn't justify the resulting bugs. I agree. -- http://mail.python.org/mailman/listinfo/python-list
Re: auto increment
On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg drsali...@gmail.com wrote: On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw mon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. There's been discussion of adding i++ to python, but it was felt that the small number of saved keystrokes didn't justify the resulting bugs. I agree. Out of curiosity, what resulting bugs? Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: auto increment
On Thu, Mar 3, 2011 at 9:07 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 3, 2011 at 9:05 PM, Dan Stromberg drsali...@gmail.com wrote: On Thu, Mar 3, 2011 at 8:48 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 3, 2011 at 8:41 PM, monkeys paw mon...@joemoney.net wrote: Does python have an analogy to c/perl incrementer? e.g. i = 0 i++ i += 1 If you're doing this for a list index, use enumerate() instead. There's been discussion of adding i++ to python, but it was felt that the small number of saved keystrokes didn't justify the resulting bugs. I agree. Out of curiosity, what resulting bugs? Cheers, Chris EG: if debug: print 'This is the %dth issue' % i++ warble = i * 65521 Then warble gets a different value depending on whether you're in debug mode or not, and the source of the problem can take a few glances to catch. Also, just using an expression in a statement context is a little... odd. I know it's the norm in some languages, but I like it that Python maintains a clear distinction. But if you disallow using an expression in a statement context, then the usefulness of i++ is dramatically decreased. -- http://mail.python.org/mailman/listinfo/python-list
Re: auto-increment operator - why no syntax error?
On Dec 8, 7:58 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote: I see python doesn't have ++ or -- operators unlike say, C. I read some reasonings talking about immutable scalars and using ++/-- doesn't make much sense in python (not sure if ++i is that far-fetched compared to the allowed i += 1) In any case, I accidentally wrote ++n in python and it silently accepted the expression and it took me a while to debug the problem. Why are the following accepted even without a warning about syntax error? (I would expect the python grammar should catch these kind of syntax errors) n = 1 2 * + n 2 n += 1 n 2 ++n 2 Karthik There is a unary operator +. When you write ++n, it's evaluating +n, and then +(that result). -- http://mail.python.org/mailman/listinfo/python-list
Re: auto-increment operator - why no syntax error?
On Sat, 08 Dec 2007 16:58:25 -0800, Karthik Gurusamy wrote: Why are the following accepted even without a warning about syntax error? (I would expect the python grammar should catch these kind of syntax errors) n = 1 2 * + n 2 n += 1 n 2 ++n 2 There is no syntax error. It is just some unary pluses chained. Maybe unexpected but no syntax error. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: auto-increment operator - why no syntax error?
--- Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 08 Dec 2007 16:58:25 -0800, Karthik Gurusamy wrote: Why are the following accepted even without a warning about syntax error? (I would expect the python grammar should catch these kind of syntax errors) 2 * + n Does pychecker catch this? Although I see why the language allows it, my guess is that most people chain unary plus operations accidentally, not intentionally. Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -- http://mail.python.org/mailman/listinfo/python-list