cleaner way to write this?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Oct 25 17:58:16 EDT 2006


John Salerno a écrit :
> Paul Rubin wrote:
> 
>> John Salerno <johnjsal at NOSPAMgmail.com> writes:
>>
>>> I just need some advice for how to structure
>>> the check of the empty string.
>>
>>
>> How about
>>
>>     return db_name or None
>>
>> since the empty string taken as a boolean is False.
> 
> 
> But if the user doesn't enter any text, I don't want the method to 
> return at all (even None). 

John, please re-read the FineManual(tm). None is the default return 
value of a function - even if there's no return statement.

 >>> def noop():
...     pass
...
 >>> assert noop() is None
 >>>




More information about the Python-list mailing list