tags:

views:

55

answers:

3

I want to replace the next expression with something simpler but i'm not sure what my changes impli?

if not (self.permission_index_link == 0) \
                                    or not (self.permission_index_link == 8):

with

if not self.permission_index_link == (0,8):
+2  A: 
if self.permission_index_link not in (0,8):
    # code

Is this what you are looking for? code will run if self.permission_index_link is not 0 or 8.

aaronasterling
+2  A: 

Are you sure your initial expression is correct? It will always be true. Didn't you mean to use and rather than or?

Use the not in operator:

if self.permission_index_link not in (0,8):
Duncan
I guess there is only one right way to do things ;)
aaronasterling
but if i use it this way will it compare to all the numbers in range of 0 to 8, or just with 0 and 8?
decebal
thanks for the head's up
decebal
It will only compare to 0, and 8. If you wanted to compare it to the range 0-8, you'd use `... not in range(0, 8)`.
Andrew
+1  A: 
if self.permission_index.link not in (0,8):
Martin