On 24/10/2021 03:48, Steven D'Aprano wrote:
On Sun, Oct 24, 2021 at 01:16:02PM +1100, Chris Angelico wrote:
And is it really a problem if we delay the late-binding to the point where the value is actually needed? Here's a toy example:
# Using only early binding. def function(spam, eggs=None, cheese=None): if eggs is None: eggs = cheap_default() # do stuff using eggs ... if condition: return result if cheese is None: cheese = expensive_default() # do stuff using cheese ... return result
-1. Too confusing. Consider def function(a, ct=>len(a)): if random.randint(0,1): a.append(42) for i in range(ct): # presumably ct may or may not be 1 more than the original length of a Best wishes Rob Cliffe