Re: more pythonic way

2019-02-16 Thread Grant Edwards
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

Re: more pythonic way

2019-02-16 Thread Barry
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

Re: more pythonic way

2019-02-11 Thread Jimmy Girardet
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): > >

Re: more pythonic way

2019-02-11 Thread Peter Otten
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: >

Re: more pythonic way

2019-02-11 Thread Peter Otten
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: >> >>

Re: more pythonic way

2019-02-11 Thread Sivan Grünberg
+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

Re: more pythonic way

2019-02-11 Thread Terry Reedy
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

RE: more pythonic way

2019-02-11 Thread David Raymond
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

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
-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

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
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

Re: more pythonic way

2019-02-11 Thread Grant Edwards
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: >