more pythonic way
Peter Otten
__peter__ at web.de
Mon Feb 11 15:40:14 EST 2019
Grant Edwards wrote:
> On 2019-02-11, Felix Lazaro Carbonell <felix at epepm.cupet.cu> wrote:
>
>> Could you please tell me wich way of writing this method is more
>> pythonic:
>>
>> def find_monthly_expenses(month=None, year=None):
>> month = month or datetime.date.today()
>>
>> Or it should better be:
>>
>> if not month:
>> month = datetime.date.today()
>
> The most pythonic way is to do this:
>
> def find_monthly_expenses(month=datetime.date.today().month,
> year=datetime.date.today().year):
> ...
>
> And then start a month-long argument on the mailing list about how the
> behavior of parameter default values is wrong and needs be changed.
>
> ;)
>
As far as arguments go I was thinking more about how this code can try and
find the december expenses when it's only january ;)
More information about the Python-list
mailing list