Help cleaning up some code

andrew cooke andrew at acooke.org
Sat Mar 7 14:05:18 CET 2009


ah, yes, i didn't see that clearly.  in this case it might be better to have:

def copy(src, dst, name, null):
 value = src[name]
 dst[name] = null if value is None else value

and then make it explicit in both cases:

copy(row, ad, name, null=None)
...
copy(row, ad, name, null='None')

andrew


Paul Rubin wrote:
> "andrew cooke" <andrew at acooke.org> writes:
>> def copy(src, dst, name, quote_none=False):
>>   value = src[name]
>>   dst[name] = 'None' if quote_none and value is None else value
>
> def copy(src, dst, name, default=None):
>   value = src[name]
>   dst[name] = value if value is not None else default
>
>>     copy(row, ad, name, quote_none=True)
>
>   copy(row, ad, name, default='None')
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>





More information about the Python-list mailing list