Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyutils module
#12
(Oct-08-2016, 02:24 AM)Mekire Wrote: 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
>>>

i am learning here.  a lot of my code is styled the way i have coded in the past.  but i am certainly open to new ways. i can adopt them faster if they can be done in all languages.  for example using only spaces and never tabs.  that works in all languages i code in.   tabs save file space but really is no issue these days. tabs save transmission time but that is no issue with broadband even at slow US speeds.  and where these are issues we have good compression that is fast on today's computers.

keep the feedback coming.  i learn more from it.  a lot of this is more than just learning the code or even how to combine different things ... it is also about learning what others prefer.

one-line functions were more about lining things up vertically.  no benefit by this? OK

i wish it were easy to break up the quote so i can respond to each issue separately. maybe MyBB has a means to insert text in a big quote and make it really look like a followup.

i did not know docstrings could be done multiple times.  how should i put licensing in?  docstrings too?

OK, so numbers.Number is the preferred way?  can you suggest better stuff for the other things, too?  i'll be switching things over to isinstance() (which means ultimately getting rid of those is*() functions).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.


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,225 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