Difference between unindexable and unsubscriptable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jackson

    #1

    Difference between unindexable and unsubscriptable

    What is the difference between "object is unindexable" and "object is
    unsubscriptable "?

    I would like to test if an object can accept: obj[0]
    >>from sets import Set
    >>Set([1,2])[0]
    TypeError: unindexable object
    >>3[0]
    TypeError: unsubscriptable object

    It seems like each of these errors can be replaced with a single type error.
  • Fredrik Lundh

    #2
    Re: Difference between unindexable and unsubscriptable

    Jackson wrote:
    What is the difference between "object is unindexable" and "object is
    unsubscriptable "?
    >
    I would like to test if an object can accept: obj[0]
    >
    >>from sets import Set
    >>Set([1,2])[0]
    TypeError: unindexable object
    >
    >>3[0]
    TypeError: unsubscriptable object
    >
    It seems like each of these errors can be replaced with a single type error.
    the message string is not part of the error type, and may change between
    versions. just catch the TypeError and be done with it.

    </F>

    Comment

    • Ben Finney

      #3
      Re: Difference between unindexable and unsubscriptable

      Jackson <jackson@hotmai l.comwrites:
      I would like to test if an object can accept: obj[0]
      Then do so. Use the object in the way you want to use it, and catch
      any exceptions that you want to handle.
      >>from sets import Set
      >>Set([1,2])[0]
      TypeError: unindexable object
      >
      >>3[0]
      TypeError: unsubscriptable object
      >
      It seems like each of these errors can be replaced with a single
      type error.
      Well, they are both merely instances of TypeError, just with a
      different message. Catching 'TypeError' will catch either of them.

      I agree, though, that it would be preferable to have the same message
      for these two cases that appear to be saying the same thing.

      --
      \ "The trouble with eating Italian food is that five or six days |
      `\ later you're hungry again." -- George Miller |
      _o__) |
      Ben Finney

      Comment

      • Theerasak Photha

        #4
        Re: Difference between unindexable and unsubscriptable

        On 10/11/06, Ben Finney <bignose+hate s-spam@benfinney. id.auwrote:
        Jackson <jackson@hotmai l.comwrites:
        >
        I would like to test if an object can accept: obj[0]
        >
        Then do so. Use the object in the way you want to use it, and catch
        any exceptions that you want to handle.
        I'm trying to learn about style conventions in Python. How would use
        of getattr compare?

        -- Theerasak

        Comment

        • Ben Finney

          #5
          Re: Difference between unindexable and unsubscriptable

          "Theerasak Photha" <hanumizzle@gma il.comwrites:
          On 10/11/06, Ben Finney <bignose+hate s-spam@benfinney. id.auwrote:
          Jackson <jackson@hotmai l.comwrites:
          I would like to test if an object can accept: obj[0]
          Then do so. Use the object in the way you want to use it, and catch
          any exceptions that you want to handle.
          >
          I'm trying to learn about style conventions in Python. How would use
          of getattr compare?
          I'm having trouble knowing what you need explained.

          You have available to you an interactive Python interpreter, and the
          documentation. Can you show us some sessions in the interpreter that
          you still find confusing after you read the relevant documentation?

          --
          \ "When I get new information, I change my position. What, sir, |
          `\ do you do with new information?" -- John Maynard Keynes |
          _o__) |
          Ben Finney

          Comment

          • Theerasak Photha

            #6
            Re: Difference between unindexable and unsubscriptable

            On 10/11/06, Ben Finney <bignose+hate s-spam@benfinney. id.auwrote:
            I'm trying to learn about style conventions in Python. How would use
            of getattr compare?
            >
            I'm having trouble knowing what you need explained.
            >
            You have available to you an interactive Python interpreter, and the
            documentation. Can you show us some sessions in the interpreter that
            you still find confusing after you read the relevant documentation?
            Don't worry, I got it now. (Ah Perl...how you warped my mind...)

            -- Theerasak

            Comment

            Working...