octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PyTave: Python object wrapper


From: Colin Macdonald
Subject: PyTave: Python object wrapper
Date: Wed, 18 May 2016 11:31:24 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]