Pythonic: Difference between revisions

1,486 bytes added ,  17 April 2016
(add note about function handles)
Line 17: Line 17:


This project is currently derived from an earlier project called Pytave, which was developed to work in the opposite direction, to allow Python to call Octave functions on an embedded Octave interpreter. The bulk of the project is in the code to convert between Octave and Python data types, so most of that is reusable and serves both purposes. As a side goal, we may continue to maintain the Python wrapper around Octave and incorporate that into Octave as well, so that Octave can provide its own native Python module.
This project is currently derived from an earlier project called Pytave, which was developed to work in the opposite direction, to allow Python to call Octave functions on an embedded Octave interpreter. The bulk of the project is in the code to convert between Octave and Python data types, so most of that is reusable and serves both purposes. As a side goal, we may continue to maintain the Python wrapper around Octave and incorporate that into Octave as well, so that Octave can provide its own native Python module.
=== Documentation ===
The current development needs to be documented. We are using doxygen for the documentation documentation.
=== Python from Octave ===
The conversion of Python's dict is not unique. For that we have decided to load a Python's dict as a structure. This works only when all the keys fo the dict are strings. When the keys are something else there is the option to use `repr` to create the fields of the Octave's struct, e.g.
<!-- {{SyntaxHighlight| -->
{{Code|Conversion of Python's dict to structure|<syntaxhighlight lang="octave" style="font-size:13px">
x = pyeval ("{1:'one',2:'two'}");
x.("1")
ans = one
x.("2")
ans = two
</syntaxhighlight>}}
This would be the default behavior. We will extend pyeval to receive an optional argument specifying the Octave type that should be used as the output of the conversion, e.g. when the dict uses continuos numbers as keys one could do
<!-- {{SyntaxHighlight| -->
{{Code|pyeval optional argument|<syntaxhighlight lang="octave" style="font-size:13px">
x = pyeval ("{1:'one',2:'two'}",@cell);
x{1}
ans = one
x{2}
ans = two
x = pyeval ("{1:'one',2:'two'}",@char);
x
x =
one
two
whos x
Variables in the current scope:
  Attr Name        Size                    Bytes  Class
  ==== ====        ====                    =====  =====
        x          2x3                          6  char
Total is 6 elements using 6 bytes
</syntaxhighlight>}}
The optional argument could be the constructor of an Octave class.
657

edits