Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyutils module
#11
Well...  quite a lot of things about that code aggravate me; most of them could be solved by making it pep8 compliant.

The main things are trying to one-line functions even when they are excessively long.
Also, you should be using docstrings for documentation, not #comments.  
#comments should be used for inline comments, or to explain specifically convoluted things that occur in the middle of a function.

For a primary example of things that annoy me take this function:
def isnum(x):           return True if 'bit_length' in dir(x) else True if 'is_integer' in dir(x) else True if 'radix' in dir(x) else False
This is onelined just for the sake of it and is using multiple ternaries to do so.

Even more so, I think you will find that this does the same thing:
from numbers import Number

#...

isinstance(thing, Number)
In fact it looks like almost all of those functions in that block could be handled with isinstance. There is no need to check the dir of an object to tell if it is a dict or not (unless you are worried about subclasses of dict being positives in which case your method won't work either).
>>> a = []
>>> b = {}
>>> isinstance(a, dict)
False
>>> isinstance(b, dict)
True
>>>


Messages In This Thread
pyutils module - by Skaperen - Oct-04-2016, 02:19 AM
RE: pyutils module - by Skaperen - Oct-04-2016, 04:48 AM
RE: pyutils module - by nilamo - Oct-04-2016, 07:39 PM
RE: pyutils module - by Skaperen - Oct-05-2016, 04:25 AM
RE: pyutils module - by nilamo - Oct-05-2016, 02:34 PM
RE: pyutils module - by Skaperen - Oct-06-2016, 12:33 AM
RE: pyutils module - by metulburr - Oct-04-2016, 07:49 PM
RE: pyutils module - by nilamo - Oct-04-2016, 07:53 PM
RE: pyutils module - by metulburr - Oct-04-2016, 07:58 PM
RE: pyutils module - by metulburr - Oct-05-2016, 11:43 AM
RE: pyutils module - by Mekire - Oct-08-2016, 02:24 AM
RE: pyutils module - by Skaperen - Oct-08-2016, 03:34 AM
RE: pyutils module - by Mekire - Oct-08-2016, 06:43 AM
RE: pyutils module - by Skaperen - Oct-08-2016, 07:05 AM
RE: pyutils module - by Mekire - Oct-08-2016, 04:48 PM
RE: pyutils module - by wavic - Oct-08-2016, 08:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyutils.py Skaperen 8 6,256 May-09-2020, 01:22 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020