Check if a given value is out of certain range

2015-09-29 Thread Laxmikant Chitare
Hi, I know there is an elegant way to check if a given value is within certain range. Example - To check if x is between zero and ten, I can do 0 < x 10. Is there any similar elegant way to check if a value is out of certain range? Example - To check if x is either less than zero or greater than

Re: Does CPython already has Peephole optimizations?

2014-02-17 Thread Laxmikant Chitare
just another opportunity. Best regards, Laxmikant On Mon, Feb 17, 2014 at 7:21 PM, Terry Reedy wrote: > On 2/17/2014 3:59 AM, Steven D'Aprano wrote: > >> On Mon, 17 Feb 2014 13:54:25 +0530, Laxmikant Chitare wrote: >> >> I read about this article: >>> h

Does CPython already has Peephole optimizations?

2014-02-17 Thread Laxmikant Chitare
Hello All, I read about this article: http://www.python.org/workshops/1998-11/proceedings/papers/montanaro/montanaro.html Just wanted to clarify whether CPython already includes these kind of byte code optimizations? Are all the temporary variables removed when byte code is generated? Regards, L

Re: "eval vs operator.methodcaller" - which is better?

2013-03-18 Thread Laxmikant Chitare
Thank you Chris, Michel and Steven for your feedback. Steven, yes I realised that the examples are faulty. I intended to use variables instead of string literals. I will be careful next time. On 3/18/13, Steven D'Aprano wrote: > On Mon, 18 Mar 2013 19:00:15 +0530, Laxmikant Chita

Re: What are some other way to rewrite this if block?

2013-03-18 Thread Laxmikant Chitare
What about this one: if 0.0 < should_be_on > 24.0 or 0.0 < came_on > 24.0: Regards, Laxmikant On 3/18/13, Santosh Kumar wrote: > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or c

Re: "eval vs operator.methodcaller" - which is better?

2013-03-18 Thread Laxmikant Chitare
Aha, that was smart Chris. Thank you. But this raises another question in my mind. What is the use case for operator.methodcaller ? On 3/18/13, Chris Angelico wrote: > On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare > wrote: >> moduleName = 'mymodule'#These two v

"eval vs operator.methodcaller" - which is better?

2013-03-18 Thread Laxmikant Chitare
Hi, I have a program that picks module and method name from a configuration file and executes the method. I have found two ways to achieve this. Apporach 1: --- moduleName = 'mymodule'#These two variables are read from conf file. methodName = 'mymethod' import operato

Re: error in except

2013-02-04 Thread Laxmikant Chitare
One more thing, apart from what Albert mentioned. Exceptions must be classes or instances. In effect you cannot just do 'raise'. 'raise' statement must be followed by a class or an instance. On Tue, Feb 5, 2013 at 6:28 AM, Albert Hopkins wrote: > > > On Mon, Feb 4, 2013, at 04:49 PM, Rodrick Br