changeset 280:3bf799e80ca5

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.
author Mike Miller <mtmiller@octave.org>
date Fri, 29 Jul 2016 20:15:39 -0700
parents 6e83efbcf1bc
children b06df69f4b37 4c4747646e12 6c133bcac33a
files @pyobject/display.m @pyobject/pyobject.m
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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')")), "<module 'sys' (built-in)>")