L
Leo Breebaart
Hi all,
I have a question about Python and delayed evaluation.
Short-circuiting of Boolean expressions implies that in:
any possible side-effects the call to b() might have will not
happen of a() returns true, because then b() will never be
executed.
However, if I go looking for dictionary keys like this:
then b() *does* get executed regardless of whether or not the
value it returns is actually used ('foo' was not found) or not
('foo' was found).
If b() has side-effects, this may not be what you want at all. It
would seem to me not too exotic to expect Python to have some
sort of construct or syntax for dealing with this, just as it
supports Boolean short-circuiting.
So I guess my question is twofold: one, do people think
differently, and if so why?; and two: is there any elegant (or
other) way in which I can achieve the delayed evaluation I desire
for setdefault, given a side-effect-having b()?
I have a question about Python and delayed evaluation.
Short-circuiting of Boolean expressions implies that in:
any possible side-effects the call to b() might have will not
happen of a() returns true, because then b() will never be
executed.
However, if I go looking for dictionary keys like this:
then b() *does* get executed regardless of whether or not the
value it returns is actually used ('foo' was not found) or not
('foo' was found).
If b() has side-effects, this may not be what you want at all. It
would seem to me not too exotic to expect Python to have some
sort of construct or syntax for dealing with this, just as it
supports Boolean short-circuiting.
So I guess my question is twofold: one, do people think
differently, and if so why?; and two: is there any elegant (or
other) way in which I can achieve the delayed evaluation I desire
for setdefault, given a side-effect-having b()?