On 2019-02-16, Barry wrote:
> On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote:
>
>>> The most pythonic way is to do this:
>>>
>>> def find_monthly_expenses(month=datetime.date.today().month,
>> year=datetime.date.today().year):
>>>...
>
> This has subtle bugs.
> The default is calcul
On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote:
>> The most pythonic way is to do this:
>>
>> def find_monthly_expenses(month=datetime.date.today().month,
> year=datetime.date.today().year):
>>...
This has subtle bugs.
The default is calculated at import time and not at function
The first one is used very often. Less verbose
Le 11 févr. 2019 à 20:41, à 20:41, Felix Lazaro Carbonell
a écrit:
>
>
>Hello to everyone:
>
>Could you please tell me wich way of writing this method is more
>pythonic:
>
>
>
>..
>
>def find_monthly_expenses(month=None, year=None):
>
>
Felix Lazaro Carbonell wrote:
> Hello to everyone:
> 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:
>
Grant Edwards wrote:
> On 2019-02-11, Felix Lazaro Carbonell 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:
>>
>>
+1 with David Raymond, it's nice to use condensed style when it leaves
things readable and logic. But if in doubt:
"Explicit is better than implicit.
Simple is better than complex." :)
-Sivan
On Mon, Feb 11, 2019 at 10:19 PM David Raymond
wrote:
> My non-expert vote is for
>
> if month is None
On 2/11/2019 2:46 PM, Felix Lazaro Carbonell wrote:
def find_monthly_expenses(month=None, year=None):
month = month or datetime.date.today().month
Or it should better be:
if not month:
month = datetime.date.today().month
As a 20+ year veteran, I would be
My non-expert vote is for
if month is None:
month = datetime.date.today().month
Because you're checking for your default value, not whether the boolean version
of what they did give you is True or False. It's explicit, it's not reliant on
any __bool__() function implementations or overrides
-Mensaje original-
De: Python-list [mailto:python-list-bounces+felix=epepm.cupet...@python.org]
En nombre de Grant Edwards
Enviado el: lunes, 11 de febrero de 2019 02:46 p.m.
Para: python-list@python.org
Asunto: Re: more pythonic way
On 2019-02-11, Felix Lazaro Carbonell wrote
Sorry I meant
..
def find_monthly_expenses(month=None, year=None):
month = month or datetime.date.today().month
..
Or it should better be:
...
if not month:
month = datetime.date.today().month
..
Cheers,
Felix.
--
https://mail.python.org/mailman
On 2019-02-11, Felix Lazaro Carbonell 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:
>
11 matches
Mail list logo