[Tutor] how to unittest cli input

Alex Kleider akleider at sonic.net
Wed Oct 14 21:20:31 CEST 2015


On 2015-10-14 11:29, Danny Yoo wrote:
>>>> ######################
>>>> def make_ask(f, l, p):
>>>>     d = {'Enter your first name: ' : f,
>>>>            'Enter your last name: ' : l,
>>>>            'Your mobile phone #: ' : p}
>>>>     return d.get
>>>> ######################
>> 
>> 
>> This is an example of a 'closure' is it not?
> 
> 
> Yes, though I try not to use the word "closure" because it's a
> technical distinction that isn't really that useful for beginners
> because it focuses on the implementation details.  That is, when we
> say the word "closure", we're emphasizing the fact that it's a
> combination of code and the data that it needs to resolve the code's
> free variables.  And for this discussion, all I really cared about was
> that we needed something that knows how to be "called".  Anything that
> distracts from that point is something I'm actively trying to avoid,
> at least at first.
> 
> 
> We could try to make the code look clever by doing something like:
> 
> ################################################
> make_ask = lambda f, l, p: (lambda key: {'Enter your first name: ' :
> f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p}[key])
> ################################################
> 
> But this would be death to the point I was trying to make.  :P

Thank you for 'making the point' and explaining it so well!
ak


More information about the Tutor mailing list