#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    3
    Rep Power
    0

    [JCads Converter] Error Found !...


    Hey Python Programmers...

    I try to create an simple program they can convert images to other images.
    Now i get an error from python if you fails with typ your image file...

    This is my script, i use PILLOW in python 3.6.2:
    Code:
    # JCads Texturics - Converter
    # ---------------------------
    # Made by Jamie van Cadsand
    from PIL import Image
    import time
    
    
    
    
    print("")
    print("JCADS TEXTURICS / CONVERTER:")
    print("")
    print("")
    
    
    # Define Defeult_Converting
    def ConvertToDefeult():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('RGB')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
            
            
            
    
    
    
    # Define Defeult_Converting
    def ConvertToTransparant():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('RGBA')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
    
    
            
    
    # Define Defeult_Converting
    def ConvertToGrayscale():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('L')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
    
    
    
    
    
    
    
    
            
    # Define Project Starter
    def startProject():
        img2assent = str(input("Converter Type: "))
        if(img2assent == "Defeult"):
            img2assent = "Defeult"
            ConvertToDefeult()
        elif(img2assent == "Transparant"):
            img2assent = "Transparant"
            ConvertToTransparant()
        elif(img2assent == "Grayscale"):
            img2assent = "Grayscale"
            ConvertToGrayscale()
        else:
            print("")
            print("Converter not Supported...")
            print("")
                    
            print("Quit JCads")
            time.sleep(1)
            quit()
            
    
    
    
    
    choose = str(input("Do you want start an project ?... 'Yes' or 'No' !: "))
    if(choose == "Yes"):
        choose = "Yes"
        print("")
        print("Setup...")
        print("")
        time.sleep(3)
        startProject()
    elif(choose == "No"):
        choose = "No"
        print("")
        print("Quit JCads...")
        time.sleep(1)
        quit()
    else:
        print("Start Project or Quit JCads...")
    This is an script to write this program in python 3.6.2, but i want to write my own error if my
    user of my program typ an failed file name (or try to load his image, including extension).

    Now python give an python error, not my own error... it happens if you try to save your
    edited image without extension... it give an python error and not my own error. I used
    excacly an IOError, but it don't works...

    Can anyone help me with my code ?... thanks, Jamie.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    3
    Rep Power
    0
    Originally Posted by JamieVanCadsand
    Hey Python Programmers...

    I try to create an simple program they can convert images to other images.
    Now i get an error from python if you fails with typ your image file...

    This is my script, i use PILLOW in python 3.6.2:
    Code:
    # JCads Texturics - Converter
    # ---------------------------
    # Made by Jamie van Cadsand
    from PIL import Image
    import time
    
    
    
    
    print("")
    print("JCADS TEXTURICS / CONVERTER:")
    print("")
    print("")
    
    
    # Define Defeult_Converting
    def ConvertToDefeult():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('RGB')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
            
            
            
    
    
    
    # Define Defeult_Converting
    def ConvertToTransparant():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('RGBA')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
    
    
            
    
    # Define Defeult_Converting
    def ConvertToGrayscale():
        print("")
        try:
            defeultImage = Image.open(input("Load Image: ")).convert('L')
    
            defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
            if(defeult == "P"):
                defeult = "P"
                defeultImage.show()
                print("")
                print("Image Preview")
                print("")
    
                quitJCads = str(input("Press any key to Quit: "))
                if(quitJCads == "Q"):
                    quitJCads = "Q"
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                else:
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            elif(defeult == "S"):
                defeult = "S"
                
                try:
                    defeultImage.save(input("Brouse Image: "))
                    print("")
                    time.sleep(1)
                    print("Succesfully Saved...")
    
                    print("")
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
                except IOError:
                    print("")
                    print("File not Found...")
                    print("")
    
                    print("Quit JCads...")
                    time.sleep(1)
                    quit()
    
            else:
                print("")
                print("Only press 'P' or 'S'...")
                print("")
    
                print("Quit JCads...")
                time.sleep(1)
                quit()
    
    
        except IOError:
            print("")
            print("File not Found")
    
    
    
    
    
    
    
    
            
    # Define Project Starter
    def startProject():
        img2assent = str(input("Converter Type: "))
        if(img2assent == "Defeult"):
            img2assent = "Defeult"
            ConvertToDefeult()
        elif(img2assent == "Transparant"):
            img2assent = "Transparant"
            ConvertToTransparant()
        elif(img2assent == "Grayscale"):
            img2assent = "Grayscale"
            ConvertToGrayscale()
        else:
            print("")
            print("Converter not Supported...")
            print("")
                    
            print("Quit JCads")
            time.sleep(1)
            quit()
            
    
    
    
    
    choose = str(input("Do you want start an project ?... 'Yes' or 'No' !: "))
    if(choose == "Yes"):
        choose = "Yes"
        print("")
        print("Setup...")
        print("")
        time.sleep(3)
        startProject()
    elif(choose == "No"):
        choose = "No"
        print("")
        print("Quit JCads...")
        time.sleep(1)
        quit()
    else:
        print("Start Project or Quit JCads...")
    This is an script to write this program in python 3.6.2, but i want to write my own error if my
    user of my program typ an failed file name (or try to load his image, including extension).

    Now python give an python error, not my own error... it happens if you try to save your
    edited image without extension... it give an python error and not my own error. I used
    excacly an IOError, but it don't works...

    Can anyone help me with my code ?... thanks, Jamie.


    Ohhh... this is my error:

    Code:
    JCADS TEXTURICS / CONVERTER:
    
    
    Do you want start an project ?... 'Yes' or 'No' !: Yes
    
    Setup...
    
    Converter Type: Defeult
    
    Load Image: Sources\Kroon.png
    Press 'P' to Preview or 'S' to Save: S
    Brouse Image: C:\Users\Gebruiker\Desktop\Renders\Result
    Traceback (most recent call last):
      File "C:\Users\Gebruiker\Desktop\Software\Python\Ware\lib\site-packages\PIL\Image.py", line 1911, in save
        format = EXTENSION[ext]
    KeyError: ''
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\Gebruiker\Desktop\Projects\Python\Python Project\Project JCads\JCads Texturics\JCTex Converting.py", line 262, in <module>
        startProject()
      File "C:\Users\Gebruiker\Desktop\Projects\Python\Python Project\Project JCads\JCads Texturics\JCTex Converting.py", line 235, in startProject
        ConvertToDefeult()
      File "C:\Users\Gebruiker\Desktop\Projects\Python\Python Project\Project JCads\JCads Texturics\JCTex Converting.py", line 49, in ConvertToDefeult
        defeultImage.save(input("Brouse Image: "))
      File "C:\Users\Gebruiker\Desktop\Software\Python\Ware\lib\site-packages\PIL\Image.py", line 1913, in save
        raise ValueError('unknown file extension: {}'.format(ext))
    ValueError: unknown file extension: 
    >>>
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,888
    Rep Power
    509
    The error, as it says in the error message, was a key error. There was no file type, the dictionary key consequently was an empty string, which isn't associated with an image format.

    While trapping the exception clearly a ValueError occurred.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo