[Tutor] Where to put small auxiliary function

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Jul 20 13:30:13 CEST 2012


On 20/07/2012 12:20, Jose Amoreira wrote:
> Hi Mark,
> Thanks.
>
>> [SNIP]
>>> Let me give an example:
>>>
>>> def is_odd(k):
>>>       if k % 2 == 0:
>>>           return False
>>>       else:
>>>           return True
>>
>>
>> I'll point out before anyone else does that you can write this function as a
>> one line return.  I'll leave you to work out how.  Personally I prefer the
>> longer version but each to their own.
>>
>
> OK, but if I wrote it as an one-liner, then it wouldn't be much use as
> an example for my question...

I didn't say write it as a one-liner, I said write it as a one line 
return.  Joel Goldstick has provided that separately, although I confess 
that I havn't had it independantly tested :)

>
>> [SNIP]
>> Don't put it in the class.  It's a general purpose function that can be used
>> anywhere so keep it at the module level.
>>
>
> OK, thanks. That was the kind of advice I was hoping for.
> Ze
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list