POV-Ray : Newsgroups : povray.off-topic : Programming style question - specifically Python : Re: Programming style question - specifically Python Server Time
29 Jul 2024 14:24:21 EDT (-0400)
  Re: Programming style question - specifically Python  
From: Shay
Date: 17 Aug 2011 21:00:08
Message: <4e4c6418$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.