Add 'length' property to @pyobject (fixes issue #9)

#16 Merged at 89a1f5a
Deleted repository
default (9da4ca336dda)
  1. Abhinav Tripathi
  • @pyobject/pyobject.m: Add the new length property and tests

Comments (7)

  1. Abhinav Tripathi author

    @Colin Macdonald I have update the PR. our comments have disappeared.
    I was asking if we want length=1 for any object (like sys)? I guess we need length=1 only for scalars (octave 1x1 matrices which are now converted to python scalars). So, if users will never receive such a value wrapped in a pyobject then we probably don't even need the error test!?

  2. Mike Miller repo owner

    Now that pycall converts arguments of type pyobject, shouldn't using pycall here instead of pyeval and sprintf be more efficient? I would like to see more uses of pybojects as "first-class" objects that can be called and passed into functions, rather than using the back-door method everywhere.

    @Colin Macdonald thoughts?

    And yes I think we need to return a valid number for any valid object to be consistent with the rest of Octave, so any Python objects that len throws on should probably return 1.

  3. Abhinav Tripathi author

    handling the error from len would be a good use of Octave try-catch.

    Thanks. It really looks better to do it this way.
    Just for completeness sake, I would like to mention that after PR 17 is merged. This same can be achieved by:

    pyexec ("def retone() :\n    return 1");
    retone = pyeval ("retone");
    len = pycall ("getattr", x, "__len__", retone) ();