Pythonic: Difference between revisions

Jump to navigation Jump to search
234 bytes added ,  18 May 2016
(→‎Python Objects in Octave: id() is something we can use as a pointer)
Line 118: Line 118:
pyexec('d = []')                    # careful, don't lose the object to the GC
pyexec('d = []')                    # careful, don't lose the object to the GC
x.keys()                            # list the keys of the dict
x.keys()                            # list the keys of the dict
clear x                            # now the object should be GCed
clear x                            # now the object could be GCed
</syntaxhighlight>}}
</syntaxhighlight>}}


Line 129: Line 129:
Notes:
Notes:


* Seems like the relevant "pointer" is {{Codeline:id()}}.  Haven't seen yet how to access an object from its id.
* 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:id()}}, maybe called {{Codeline:__objects_in_octave__}}.  Then pass the id of the object (an int) to the {{Codeline:@pyobj/pyobj}} constructor.


* 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.
* 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.
99

edits

Navigation menu