# HG changeset patch # User Mike Miller # Date 1469848539 25200 # Node ID 3bf799e80ca5110df2871bf955c8b6eda09a862f # Parent 6e83efbcf1bc952c86faf585ea192fbb6408dd8c pyobject: add char conversion method, refactor disp and display to use char * @pyobject/pyobject.m (@pyobject/char): New method. (@pyobject/disp): Use it. * @pyobject/display.m: Use char directly instead of disp. diff -r 6e83efbcf1bc -r 3bf799e80ca5 @pyobject/display.m --- a/@pyobject/display.m Fri Jul 29 15:15:23 2016 -0700 +++ b/@pyobject/display.m Fri Jul 29 20:15:39 2016 -0700 @@ -33,7 +33,7 @@ ## @end group ## @end example ## -## @seealso{@@pyobject/disp} +## @seealso{@@pyobject/char, @@pyobject/disp} ## @end defmethod @@ -42,7 +42,7 @@ loose = ! __compactformat__ (); printf ("%s = [pyobject %s]\n", inputname (1), getid (x)); - s = disp (x); + s = char (x); s = make_indented (s); if (loose), printf ("\n"); endif disp (s) diff -r 6e83efbcf1bc -r 3bf799e80ca5 @pyobject/pyobject.m --- a/@pyobject/pyobject.m Fri Jul 29 15:15:23 2016 -0700 +++ b/@pyobject/pyobject.m Fri Jul 29 20:15:39 2016 -0700 @@ -96,8 +96,12 @@ r = x.id; endfunction + function s = char (x) + s = pycall ("str", x); + endfunction + function varargout = disp (x) - s = pyeval (sprintf ("str(__InOct__['%s'])", x.id)); + s = char (x); if (nargout == 0) disp (s) else @@ -144,3 +148,9 @@ %! pyexec ("import sys"); %! pyobj = pyeval ("sys"); %! assert (length (pyobj), 1) + +%!assert (char (pyeval ("None")), "None") +%!assert (char (pyeval ("'this is a string'")), "this is a string") +%!assert (char (pyeval ("[1, 2, 3, 4, 5]")), "[1, 2, 3, 4, 5]") +%!assert (char (pyeval ("(1, 2, 3, 4, 5)")), "(1, 2, 3, 4, 5)") +%!assert (char (pyeval ("__import__('sys')")), "")