Python Forum
testing for Decimal w/o importing decimal every time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
testing for Decimal w/o importing decimal every time
#6
(May-06-2019, 06:42 AM)Skaperen Wrote: i think that would either end up with a lot of extra code, or a more twisty maze of function calls
I don't know your code, so you should know better and I just speculate, but the whole point of singledispatch is to have same function call and it will be different function depending on first argument type.

(May-06-2019, 06:42 AM)Skaperen Wrote: it's just a difference in how i shift the decimal point around when there is a whole value there during conversion to string. about 80 lines of code does the same thing for (int,float,Decimal). it's complex when .imag is non-zero and Fraction that will be my future mess.

Again, I can just speculate, but I think it's mess exactly because you try to keep everything in one function and thus use a lot of if statements depending on type. I think, even with some repeating parts, that you cannot put in a separate function to avoid repeting, it will be easier and you will end up with more readable and structured code to deal if for each type you have different function and it's strightforward
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: testing for Decimal w/o importing decimal every time - by buran - May-06-2019, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Precision with Decimal Type charlesrkiss 9 816 Jan-18-2024, 06:30 PM
Last Post: charlesrkiss
  Python Struct Question, decimal 10, \n and \x0a. 3python 2 689 Aug-11-2023, 09:29 AM
Last Post: 3python
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,140 Dec-06-2022, 11:09 AM
Last Post: mg24
  method to remove zero digits from fraction in decimal Skaperen 17 2,860 Oct-23-2022, 04:02 AM
Last Post: Skaperen
  Decimal context stevendaprano 1 1,072 Apr-11-2022, 09:44 PM
Last Post: deanhystad
  decimal comma DPaul 9 2,334 Feb-22-2022, 12:25 PM
Last Post: DeaD_EyE
  Conversion from hexa to decimal in loop bugging Personne 1 1,302 Feb-22-2022, 04:32 AM
Last Post: deanhystad
  Calculate the Euler Number with more decimal places Pedroski55 10 4,617 Oct-31-2021, 04:45 AM
Last Post: Pedroski55
  idle and characters with decimal value>127 hakelm 14 4,534 Jun-19-2021, 07:32 AM
Last Post: hakelm
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,370 May-07-2021, 12:39 AM
Last Post: MDRI

Forum Jump:

User Panel Messages

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