osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

more pythonic way


+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 <David.Raymond at tomtom.com>
wrote:

> 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, etc.
>
>
> -----Original Message-----
> From: Python-list [mailto:python-list-bounces+david.raymond=
> tomtom.com at python.org] On Behalf Of Felix Lazaro Carbonell
> Sent: Monday, February 11, 2019 2:30 PM
> To: python-list at python.org
> Subject: more pythonic way
>
>
>
> 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:
>
>             month = datetime.date.today()
>
> ..
>
>
>
> Cheers,
>
> Felix.
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Sivan Greenberg
Co founder & CTO
Vitakka Consulting