On Sat, May 30, 2009 at 10:55:50AM +0000, feldmaus wrote:
Hi All again,
list comprehension doesnt work in variables, for example:
[print(i) for i in range(3)]
“print” is a statement, not a function.
I’d probably use:
for i in range(3): print i
variable_2 = file(’…/…/…/tabs.dat’,‘w’)
([variable_2.write(str(i)) for i in [1,2]] is True) &
(variable_2.close() is True)
([v2.write(str(i)) for i in [1,2]] is True) and v2.close() is True
will of course always be False, since [None, None] is not True
It looks like you are trying to abuse list comprehensions for some kind
of control flow short cut. I think of them as an equivalent to the
“map” builtin, a higher-order function.
You may want to consider “map” and “reduce” in combination.