Thursday, September 3, 2020

Not counting zeros

We all have our favorite way of intentionally raising an exception in Python. Some like referencing an undefined variable to get a simple NameError, others might import a module that doesn't exist for a bold ImportError.

But the tasteful exceptioneer knows to reach for that classic computer-confounding conundrum: 1/0 for a satisfyingly descriptive DivisionByZero.

So, when does dividing by 0 not raise DivisionByZero?

Why, when you divide 0 by a Decimal(0), of course!

>>> from decimal import Decimal
>>> Decimal(0) / Decimal(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]
>>> Decimal(1) / Decimal(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
decimal.DivisionByZero: [<class 'decimal.DivisionByZero'>]

The numerator type doesn't seem to matter either:

>>> 0 / Decimal(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]

"InvalidOperation" just doesn't quite have the same ring to it! Well, they can't all be heroes. :)

52 comments:

  1. You get an undefined error because decimal cannot handle NaNs.
    If you do 1 / decimal.Decimal(0) you will get a division by zero error.

    ReplyDelete
    Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. Actually, I'm wrong, the decimal package can handle both infinity and NaN.

    a = decimal.Decimal(float('Inf'))
    b = decimal.Decimal(float('NaN'))

    The operations are just inconsistent, as seems to be the standard in Python…

    https://wiesmann.codiferes.net/wordpress/?p=13366

    ReplyDelete

  3. It is very ideal to see the best subtleties introduced in a simple and getting way. 360DigiTMG project management training

    ReplyDelete
  4. I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
    360DigiTMG big data analytics courses

    ReplyDelete
  5. He gathers all the necessary facts and information before finding a solution to a problem.
    https://360digitmg.com/course/certification-on-robotic-process-automation-rpa

    ReplyDelete
  6. I at long last discovered extraordinary post here.I will get back here. I just added your blog to my bookmark destinations. thanks.Quality presents is the significant on welcome the guests to visit the website page, that is the thing that this page is giving.
    data scientist course

    ReplyDelete
  7. Thanks for posting the best information and the blog is very informative.Data science course in Faridabad

    ReplyDelete
  8. Very awesome!!! When I searched for this I found this website at the top of all blogs in search engines.

    Best Institutes For Digital Marketing in Hyderabad

    ReplyDelete
  9. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one
    Best Data Science courses in Hyderabad

    ReplyDelete
  10. I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
    data analytics courses in bangalore

    ReplyDelete
  11. Thanks for posting the best information and the blog is very helpful.digital marketing institute in hyderabad

    ReplyDelete
  12. your blog everyday and try to learn something from your blog. Thank you and I'm waiting for your new post.
    best data science institute in hyderabad

    ReplyDelete
  13. This website and I conceive this internet site is really informative ! Keep on putting up!
    data science course in pune

    ReplyDelete
  14. Thanks for posting the best information and the blog is very important.data science institutes in hyderabad

    ReplyDelete
  15. I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
    Data Science Course Syllabus

    ReplyDelete
  16. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

    DevOps Training in Hyderabad

    ReplyDelete
  17. i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
    artificial intelligence training in chennai

    ReplyDelete
  18. Tremendous blog quite easy to grasp the subject since the content is very simple to understand. Obviously, this helps the participants to engage themselves in to the subject without much difficulty. Hope you further educate the readers in the same manner and keep sharing the content as always you do.

    data science course in faridabad

    ReplyDelete
  19. Your website is really cool and this is a great inspiring article.
    data science course in malaysia

    ReplyDelete
  20. Thanks for posting the best information and the blog is very good.data science course in Lucknow

    ReplyDelete
  21. It was a very good post indeed. I thoroughly enjoyed reading it in my lunch-time. I Will surely come and visit this blog more often. Feel free to visit my website; 온라인카지노사이트

    ReplyDelete
  22. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good. Thanks a lot! Feel free to visit my website; 카지노사이트링크

    ReplyDelete
  23. I like this website its a master peace ! Glad I found this on google . I must say, as a lot as I enjoyed reading what you had to say, I couldn't help but lose interest after a while. Feel free to visit my website; 온라인카지노사이트넷

    ReplyDelete
  24. I must thank you for the efforts you’ve put in writing this blog. I am hoping to view the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has inspired me to get my very own blog now ?? Thank you for the auspicious writeup Feel free to visit my website; 바카라사이트닷컴

    ReplyDelete
  25. A great website with interesting and unique material what else would you need.
    data scientist certification malaysia

    ReplyDelete
  26. Nice blog! Thanks for sharing such a great blog. whatsapp mod

    ReplyDelete
  27. IT is a informative and learnable blog site .Thank you so much for sharing this post.
    Best Software Company in Bangladesh

    ReplyDelete
  28. Thank you very much for publishing this of article, I like your article very much. Your post is very informative and helpful. dehumidifier supplier in Bangladesh

    ReplyDelete
  29. Infycle Technologies offers couples for care and technology in addition to Python Training in Chennai, 100% of the internship class will be prepared. After completing the training, the participants will be sent to the upper MNCs interviews. Call 750633333 to get more information and get a free display.

    ReplyDelete
  30. Your blog site is really one of the blog sites I have visited. I hope you get some better updates. Thank you so much for sharing this post with us. Thank you.dehumidifier price in Bangladesh

    ReplyDelete
  31. Your blog site is very informative and learnable site . Thank you so much for sharing this post with us .

    ReplyDelete
  32. While looking for articles on these topics, I came across this article on the site here. As I read your article, I felt like an expert in this field. I have several articles on these topics posted on my site. Could you please visit my homepage? 토토사이트모음

    ReplyDelete
  33. I accidentally searched and visited your site. I still saw several posts during my visit, but the text was neat and readable. I will quote this post and post it on my blog. Would you like to visit my blog later? 토토사이트순위

    ReplyDelete
  34. Thank you very much for publishing this of article, I like your article very much. Your post is very informative and helpful. Best Software Company in Bangladesh

    ReplyDelete
  35. Your ideas inspired me very much. 메이저토토사이트모음 It's amazing. I want to learn your writing skills. In fact, I also have a website. If you are okay, please visit once and leave your opinion. Thank you.

    ReplyDelete
  36. Wow, very nice blog site. Really this is one of the best blog site I am very impressed with your post. Thank you so much for sharing this post. diploma in engineering

    ReplyDelete
  37. Really it is a very interesting blog site. And your posts are very beautiful, I am very impressed for your post. And thank you so much for sharing this post web development company in Bangladesh

    ReplyDelete
  38. Nice post love it check my site for fast Satta King we provide superfast and all time result SattaKing

    ReplyDelete

  39. Thank you very much for publishing this of article, I like your article very much. Your post is very informative and helpful. web development company in Bangladesh

    ReplyDelete
  40. I just found your post by searching on google, I'm fascinated and learned a lot of new things from your post. I try to learn new and always new skills in blogging because I believe that blogging is a full-time job to learn new things day in and day out. Thank you so much for sharing this post with us web development company in Bangladesh


    ReplyDelete
  41. The term Internet Service Provider (ISP) refers to a company that provides Internet access to both personal and business customers. ISPs make it possible for their clients to surf the web, shop online, runs a business, and connect with family and friends - in exchange for everything. ISPs can also provide other services including email services, domain registration, web hosting and browser packages. Our blog site is related to Internet Service Provider (ISP). I believe that my blog site is more helpful than all other blog sites. We provide the best service to everyone. best isp in Dhaka

    ReplyDelete
  42. Slope is the most exciting speed game. At first glance, the game may seem simple, but you should try to play it at least once. You will not notice how you spend several hours enthusiastically playing it. The game developers have thought through every detail so that you not only play the game but also develop your reaction. The simple design of the Slope unblocked games will not overload your visual channel, so you can play it for several hours and not feel exhausted. This game is suitable for both young children and adults - it is universal and will interest any player.

    ReplyDelete
  43. Thank you so much for sharing this great blog. Very inspiring and helpful too. Hope you continue to share more of your ideas.I will definitely love to read.
    토토사이트
    온라인경마

    ReplyDelete