r/Python • • Jun 23 '14

Writing better python code

https://gist.github.com/kracekumar/09a60ec75a4de19b346e
143 Upvotes

126 comments sorted by

View all comments

0

u/[deleted] Jun 23 '14

[deleted]

3

u/cdcformatc Jun 23 '14

I object to if super_users: over if len(super_users) > 0: There is a huge difference between an empty list and None. If you want to check that the length of the list is greater than zero you should... just do that.

A lot of this reads like "Abuse syntax to make your code look more Pythonic" and treats Pythonic like some lofty goal. A lot of "Pythonic" code is just harder to read, it isn't an end in itself.

7

u/quasarc Jun 23 '14

I object to if super_users: over if len(super_users) > 0: There is a huge difference between an empty list and None.

Both of these tests can only be used if you know that super_users is a list and not None.

Using if super_users: is not abusing syntax, it just uses the intended and well-known fact that non-empty sequences are true. (It's also recommended by the style guide PEP8.)