Mercurial > pytave
changeset 237:89a1f5a82467
Merged in genuinelucifer/pytave_main (pull request #16)
Add 'length' property to @pyobject (fixes issue #9)
author | Mike Miller <mike@mtmxr.com> |
---|---|
date | Fri, 22 Jul 2016 10:23:40 -0700 |
parents | bbf0b7a4e117 (current diff) 9da4ca336dda (diff) |
children | c64435b14a6e 0401489ea58c |
files | |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobject/pyobject.m Thu Jul 21 00:49:37 2016 -0700 +++ b/@pyobject/pyobject.m Fri Jul 22 10:23:40 2016 -0700 @@ -118,6 +118,14 @@ vargout = {s}; endif endfunction + + function len = length (x) + try + len = pycall ("len", x); + catch + len = 1; + end_try_catch + endfunction endmethods endclassdef @@ -126,3 +134,13 @@ %! pyexec ("import sys") %! A = pyeval ("sys"); %! assert (isa (A, "pyobject")) + +%!test +%! pyobj = pyeval ("{1:2, 2:3, 3:4}"); +%! assert (isa (pyobj, "pyobject")) +%! assert (length (pyobj), 3) + +%!test +%! pyexec ("import sys"); +%! pyobj = pyeval ("sys"); +%! assert (length (pyobj), 1)