comparison @pyobject/pyobject.m @ 222:e2e64ee571b7

pyobject: rename whatmethods to methods (fixes #21) Usually `methods` would give the methods of the Octave class. Here we use it to get the properties/callables of a Python object. Add documentation which explains how to get the former behaviour. Add BIST. @pyobject/pyobject.m: remove original function @pyobject/methods.m: new file
author Colin Macdonald <cbm@m.fsf.org>
date Fri, 17 Jun 2016 16:13:36 -0700
parents a76d75683455
children 06835a3e3384
comparison
equal deleted inserted replaced
221:a76d75683455 222:e2e64ee571b7
106 106
107 function s = whatclass (x) 107 function s = whatclass (x)
108 s = pyeval (sprintf ('str(__InOct__["%s"].__class__)', x.id)); 108 s = pyeval (sprintf ('str(__InOct__["%s"].__class__)', x.id));
109 end 109 end
110 110
111 function lst = whatmethods (x)
112 % filter the output of `dir(x)`
113 % properties only:
114 % [a for a in dir(x) if not callable(getattr(x, a)) and not a.startswith("__")]
115 cmd = sprintf ( ...
116 '[a for a in dir(__InOct__["%s"]) if not a.startswith("__")]', ...
117 x.id);
118 lst = pyeval (cmd);
119 end
120
121 function vargout = help (x) 111 function vargout = help (x)
122 idx = struct ('type', '.', 'subs', '__doc__'); 112 idx = struct ('type', '.', 'subs', '__doc__');
123 s = subsref (x, idx); 113 s = subsref (x, idx);
124 if (nargout == 0) 114 if (nargout == 0)
125 disp (s) 115 disp (s)