Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retry After Exception
#1
Hey! Friends I coded a program with a external module called tenacity
Problem: I want to retry After Exception
Here Is The Code:
from tenacity import *
from ast import literal_eval
import time
print("Welcome To Decimal To Hex Or Binary Converter")
def line():
    for i in range(50):
        print("-",end='')
print("\nPlease Type The 'h' for hex input")
line()
print("\nPlease Type The 'd' for decimal input")
line()
print("\nPlease Type The 'b' for binary input")
line()
temp = input("\nType 'h' or 'd' or 'b':")
line()
time.sleep(1)
print(f"\nSo You type '{temp}'")
time.sleep(0.1)
@retry(stop=stop_after_attempt(2),retry=retry_any())
def starting():
    for i in temp:
        if i == 'h':
            try:
                time.sleep(1)
                hexa = input("\nPlease Type The Hex Input To Convert Into Deciaml And Binary:")
                time.sleep(1)
                print(f"In The Decimal Form: %s" %(literal_eval(hexa)))
                print(f"In The Binary Form: %s" %(bin(int(hexa,16))))
                time.sleep(5)
            except ValueError:
                print("Only Hex Numbers!")
                print("Hex Numbers Look Like 0x1,0x3, etc.")
                time.sleep(5)
                line()
        elif i == 'd':
            line()
            time.sleep(1)
            print("\nEntering Decimal Mode")
            time.sleep(1)
            line()
            time.sleep(1)
            deci = input("\nPlease Type The Decimal Input To Convert Into Hex And Binary:")
            try:
                time.sleep(1)
                print(f"In The Hexadecimal Form: %s" %(int(deci)))
                print(f"In The Binary Form: %s" %(bin(int(deci,16))))
                time.sleep(5)
            except ValueError:
                print("Only Decimal And Integers Accepted!")
                print("Type Some Simple Numbers like 1,2,3, etc.")
                line()
                time.sleep(5)
        elif i == 'b':
            line()
            time.sleep(1)
            print("\nEntering Binary Form")
            line()
            time.sleep(1)
            bina = input("\nType The Binary Input To Convert In Hexadecimal And Decimal Form:")
            line()
            try:
                time.sleep(1)
                print("\nIn The HexaDecimal Form: %s" %(hex(int(bina,2))))

            except ValueError:
                print("\nOnly Binary Numbers:")
        else:
            print("Please Only Select From 'h' or 'd' or 'b' ")
            time.sleep(5)
starting()
Reply


Messages In This Thread
Retry After Exception - by Harshil - Aug-09-2020, 01:24 PM
RE: Retry After Exception - by deanhystad - Aug-09-2020, 03:20 PM
RE: Retry After Exception - by Harshil - Aug-09-2020, 05:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Use function, retry until valid Ashcora 8 1,494 Jan-06-2023, 10:14 AM
Last Post: Ashcora
  How to ignore "Retrying (Retry(total=2, connect=2, read=5, redirect=5, status=None))" const 3 2,765 Mar-26-2022, 08:55 AM
Last Post: ndc85430
  requests_futures.sessions retry list of HTTP 429 Johanoosterwaal 0 1,577 Nov-20-2020, 09:23 PM
Last Post: Johanoosterwaal
  How can I fix this code so if i want to retry, it will go through the same loop SteampunkMaverick12 1 1,903 Apr-15-2019, 07:36 PM
Last Post: ichabod801
  During handling of the above exception, another exception occurred Skaperen 7 26,946 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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