|
![](/i/fill.gif) |
On Wed, 17 Aug 2011 14:12:02 -0300, nemesis wrote:
> Shay escreveu:
>> How would I best type the following:
>>
>> if long_condition1 or (long_condition2 and long_condition3):
>>
>> Without making a complete, unreadable mess.
>>
>> some_name = long_conditionn # bool
>>
>> will not work, because I can't evaluate long_condition2 if 1 is true.
>
> what's the problem people have with parentheses?
No problem with parenthesis. But Python is a little funny about spacing.
A = [0, 1]
B = [0, 1]
C = [0, 1]
D = [0, 1]
List = [A, B, C, D]
if (
some_funk(x for x in List) or
(
some_other_func(x for x in List) and
a_third_func(x for x in List))):
That's legal(ish), but now I'm screwed with my indentation.
if (
some_funk(x for x in List) or
(some_other_func(x for x in List) and
a_third_func(x for x in List))):
print("execute code here")
How I ended up going, but it's still a little hairy to read.
Then I though about it a bit more and went with:
my_bool = (
some_funk(x for x in List) or
(
some_other_func(x for x in List) and
a_third_func(x for x in List)))
if my_bool:
print("execute code here")
-Shay
Post a reply to this message
|
![](/i/fill.gif) |