209
|
1 %% Copyright (C) 2016 Colin B. Macdonald |
|
2 %% |
|
3 %% This file is part of PyTave. |
|
4 %% |
|
5 %% OctSymPy is free software; you can redistribute it and/or modify |
|
6 %% it under the terms of the GNU General Public License as published |
|
7 %% by the Free Software Foundation; either version 3 of the License, |
|
8 %% or (at your option) any later version. |
|
9 %% |
|
10 %% This software is distributed in the hope that it will be useful, |
|
11 %% but WITHOUT ANY WARRANTY; without even the implied warranty |
|
12 %% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
|
13 %% the GNU General Public License for more details. |
|
14 %% |
|
15 %% You should have received a copy of the GNU General Public |
|
16 %% License along with this software; see the file COPYING. |
|
17 %% If not, see <http://www.gnu.org/licenses/>. |
|
18 |
|
19 %% -*- texinfo -*- |
|
20 %% @documentencoding UTF-8 |
|
21 %% @defmethod @@pyobject dummy (@var{x}) |
|
22 %% Does nothing, stores doctests for now. |
|
23 %% |
|
24 %% |
|
25 %% Simple example: |
|
26 %% @example |
|
27 %% @group |
|
28 %% pyexec('g = 6') |
|
29 %% g = pyobject.fromPythonVarName('g'); |
|
30 %% |
|
31 %% sort(whatmethods(g)) |
|
32 %% @result{} ans = |
|
33 %% @{ |
|
34 %% [1,1] = bit_length |
|
35 %% [1,2] = conjugate |
214
|
36 %% [1,3] = denominator |
|
37 %% [1,4] = imag |
|
38 %% [1,5] = numerator |
|
39 %% [1,6] = real |
209
|
40 %% @} |
|
41 %% |
|
42 %% g.numerator |
|
43 %% @result{} ans = 6 |
|
44 %% g.denominator |
|
45 %% @result{} ans = 1 |
|
46 %% @end group |
|
47 %% @end example |
|
48 %% |
|
49 %% |
|
50 %% You can delete an object in Python and it will persist: |
|
51 %% @example |
|
52 %% @group |
|
53 %% pyexec('d = dict(one=1, two=2)') |
|
54 %% x = pyobject.fromPythonVarName('d') |
|
55 %% @result{} x = |
|
56 %% [PyObject id ...] |
|
57 %% @{'two': 2, 'one': 1@} |
|
58 %% |
|
59 %% % oops, overwrote d in Python: |
|
60 %% pyexec('d = 42') |
|
61 %% |
|
62 %% % but have no fear, we still have a reference to it: |
|
63 %% x |
|
64 %% @result{} x = |
|
65 %% [PyObject id ...] |
|
66 %% @{'two': 2, 'one': 1@} |
|
67 %% @end group |
|
68 %% @end example |
|
69 %% |
|
70 %% We can accesss ``callables'' (methods) of objects: |
|
71 %% @example |
|
72 %% @group |
|
73 %% x.keys() |
|
74 %% @result{} ans = |
|
75 %% @{ |
|
76 %% [1,1] = two |
|
77 %% [1,2] = one |
|
78 %% @} |
|
79 %% @end group |
|
80 %% @end example |
|
81 %% |
|
82 %% @code{pyeval} returns a @@pyobject for things it cannot convert to |
|
83 %% Octave-native objects: |
|
84 %% @example |
|
85 %% @group |
|
86 %% pyexec('import sys') |
|
87 %% sysmodule = pyeval('sys') |
|
88 %% @result{} sysmodule = |
|
89 %% [PyObject id ...] |
|
90 %% <module 'sys' (built-in)> |
|
91 %% @end group |
|
92 %% @end example |
|
93 %% |
|
94 %% After you have the object, you can access its properties: |
|
95 %% @example |
|
96 %% @group |
|
97 %% sysmodule.version |
|
98 %% @result{} ans = ... |
|
99 %% @end group |
|
100 %% @end example |
|
101 %% |
|
102 %% |
|
103 %% TODO: this should return a cell array with a double, a string, |
|
104 %% and an @@pyobject in it: |
|
105 %% @example |
|
106 %% @group |
|
107 %% pyeval('[42, "hello", sys]') % doctest: +XFAIL |
|
108 %% @result{} ans = |
|
109 %% @{ |
|
110 %% [1,1] = 42 |
|
111 %% [1,2] = hello |
|
112 %% [1,3] = |
|
113 %% [PyObject id ...] |
|
114 %% <module 'sys' (built-in)> |
|
115 %% @} |
|
116 %% @end group |
|
117 %% @end example |
|
118 %% |
|
119 %% @seealso{pyobject} |
|
120 %% @end defmethod |
|
121 |
|
122 function dummy (x) |
|
123 |
|
124 end |