PyTave: Python object wrapper

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PyTave: Python object wrapper

Colin Macdonald-2
Mike (et al),

I tried making an m-file classdef wrapper around Python objects.

Its the "cbm_pyobj" bookmark on my bitbucket.  I don't see how to link
to a "head", but here's the only commit so far:

https://bitbucket.org/macdonald/pytave/commits/4b3504905b751ba00f1151585126fdc907c78262

This is very rough so far (its only about 25 lines).  It assumes the
variable name on the Python side will stick around, so very fragile...
I will put some ideas for discussion on the wiki now.

- - - - -

Here's an example, accessing *properties* of a Python Object

>> pyexec('g = 6')
>> g = pyobj('g')
g =

PyObject with repr:
  6
original variable: g

>> whatclass(g)
ans = <type 'int'>

>> whatmethods(g)
ans =
{
  [1,1] = denominator
  [1,2] = imag
  [1,3] = numerator
  [1,4] = real
}
>> g.numerator
ans =  6
>> g.denominator
ans =  1
>>


One think that doesn't work yet is *calling* methods of a Python Object:

>> pyexec('d = dict(one=1, two=2)')
>> d = pyobj('d')
d =

PyObject with repr:
  {'two': 2, 'one': 1}
original variable: d

>> d.keys()
error: binary operator '==' not implemented for 'cs-list' by 'matrix'
operations
error: called from
    subsref at line 60 column 7


best,
Colin