Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:54:42+00:00 2026-06-16T05:54:42+00:00

i wish to improve the following function. Given a Pixel data types in GDAL

  • 0

i wish to improve the following function. Given a Pixel data types in GDAL (ex: "Int16") resturn a code number.

def GDAL_data_type(dataType):
    dtypes = {
        "Unknown": 0,
        "Byte": 1,
        "UInt16": 2,
        "Int16": 3,
        "UInt32": 4,
        "Int32": 5,
        "Float32": 6,
        "Float64": 7,
        "CInt16": 8,
        "CInt32": 9,
        "CFloat32": 10,
        "CFloat64": 11
        }
    return dtypes[dataType]

GDAL_data_type("Int16")
3

I wish to insert a error message in the function where if you type a dataType different, the error message say:

raise SystemExit('Pixel data type no recognized %s' % dataType)

I wish to ask the best way to insert this error message in my function. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:54:43+00:00Added an answer on June 16, 2026 at 5:54 am

    Wrap the dictionary lookup in a try block, catch the keyerror exception, and raise your own from the catch block:

    try:
      return dtypes[dataType]
    except KeyError:
      raise ...
    

    EDIT

    Or more fully:

    def GDAL_data_type(dataType):
        dtypes = {
            "Unknown": 0,
            "Byte": 1,
            "UInt16": 2,
            "Int16": 3,
            "UInt32": 4,
            "Int32": 5,
            "Float32": 6,
            "Float64": 7,
            "CInt16": 8,
            "CInt32": 9,
            "CFloat32": 10,
            "CFloat64": 11
            }
        try:
            return dtypes[dataType]
        except KeyError:
            raise ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to improve my code and file structure in larger Win32 projects with
I wish to return from the following powershell function if I find a match
I wish fetch data in a XML file, where Tag is a variable.. My
To improve the security for my users I wish to hide all user-passwords in
I wish to call a method in my code behind from JavaScript, I sort
The following code snippet is needed to capture html links for my site. Although,
I wish to stop a token parser when the semantic action code finds a
I am ingesting an AWT image (from PDF, through PDFBox) with the following code:
I wish to make the uploaded file contents only viewable on the browser i.e
I wish to do this using only XAML - How to add an additional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.