Changes

Jump to navigation Jump to search

Pythonic

1,554 bytes removed, 21:02, 18 August 2016
→‎Python Objects in Octave: clean-up pyobj section: this is basically working, rather than design
==== Python Objects in Octave ====
The {{Codeline|@pyobjpyobject}} classdef class is intended to wrap wraps arbitrary Python objects so they can be accessed an and manipulated from within Octave. {{Code|avoiding garbage collection|<syntaxhighlight lang="octave" style="font-size:13px" line highlight="4">pyexec('d = dict(one=1, two=2)') # create object in Pythonx = pyobj('d') # create pyobj wrapper for that objectpyexec('d = []') # careful, don't lose the object to the GCx.keys() # list the keys of the dictclear x # now the object could be GCed</syntaxhighlight>}} One proposed way to do this: 1. `x` stores the pointer to `d`. The `@pyobj` ctor creates a dummy reference to `d`, this prevents GC 2. on deletion of x (`clear x`) we delete the dummy reference in Python. Notes: * Seems like the relevant "pointer" is {{Codeline|id()}}. Haven't seen yet how to access an object from its id, except that its a bad idea... * My plan to create a dict in Python, indexed by {{Codeline|hex(id(x))}}In most cases, maybe called {{Codeline|__InOct__}}. Then pass the id of the object to the {{Codeline|@pyobj/pyobj}} constructor. * Follow along and help out here: https://bitbucket.org/macdonald/pytave/commits/branch/cbm_pyobj * Rejected idea: store the `repr` as a string in `x`. But this makes a copy of the object rather than a reference to the original object. ====== Interface design ====== * {{Codeline|pyeval}} should be modified to return a {{Codeline|@pyobj}} for things that it cannot convert to Octave-native types. See the `networkx` example above: `G` could be returned by `pyeval`. * {{Codeline|@pyobj/pyobj}} constructor would not normally be called by usersthese are created automatically.
== Known Problems ==
64

edits

Navigation menu