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
#5
(May-06-2019, 12:04 AM)Gribouillis Wrote: Why not if hasattr(x, 'radix'):...?

better way to code it; same idea. i guess this technique risks a user-defined object that has attribute 'radix' for whatever reason.

(May-06-2019, 04:39 AM)buran Wrote: IMHO, importing it is much better than writing some weird test for type. Then depending on how different the function should be you can use @functools.singledispatch(yet another import)

i think that would either end up with a lot of extra code, or a more twisty maze of function calls i would have to figure out to avoid the duplication. 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.
Tradition is peer pressure from dead people

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


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Precision with Decimal Type charlesrkiss 9 819 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,142 Dec-06-2022, 11:09 AM
Last Post: mg24
  method to remove zero digits from fraction in decimal Skaperen 17 2,862 Oct-23-2022, 04:02 AM
Last Post: Skaperen
  Decimal context stevendaprano 1 1,074 Apr-11-2022, 09:44 PM
Last Post: deanhystad
  decimal comma DPaul 9 2,335 Feb-22-2022, 12:25 PM
Last Post: DeaD_EyE
  Conversion from hexa to decimal in loop bugging Personne 1 1,303 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,535 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,371 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