comparison @pyobject/dummy.m @ 313:01ff03fef237

Update docs for recent changes * @pyobject/dummy.m: Update doctests.
author Colin Macdonald <cbm@m.fsf.org>
date Tue, 09 Aug 2016 19:16:59 -0700
parents 72ecb31b163a
children 15c20ab4b80a
comparison
equal deleted inserted replaced
312:d9f9156a13c9 313:01ff03fef237
17 ## If not, see <http://www.gnu.org/licenses/>. 17 ## If not, see <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @documentencoding UTF-8 20 ## @documentencoding UTF-8
21 ## @defmethod @@pyobject dummy (@var{x}) 21 ## @defmethod @@pyobject dummy (@var{x})
22 ## Does nothing, stores doctests for now. 22 ## Does nothing, stores doctests and other misc docs for now.
23 ## 23 ##
24 ## 24 ##
25 ## Simple example: 25 ## Some simple Python objects are converted to equivalent Octave values:
26 ## @example
27 ## @group
28 ## pyeval ("6")
29 ## @result{} ans = 6
30 ## @end group
31 ## @end example
32 ##
33 ## To ensure the return value is a @@pyobject, it can be cast:
26 ## @example 34 ## @example
27 ## @group 35 ## @group
28 ## g = pyobject (int32 (6)) 36 ## g = pyobject (int32 (6))
29 ## @result{} g = [pyobject ...] 37 ## @result{} g = [pyobject ...]
30 ## 38 ##
55 ## 63 ##
56 ## 64 ##
57 ## You can delete an object in Python and it will persist: 65 ## You can delete an object in Python and it will persist:
58 ## @example 66 ## @example
59 ## @group 67 ## @group
60 ## pyexec ("d = dict(one=1, two=2)") 68 ## pyexec ("d = dict(two=2)")
61 ## x = pyobject.fromPythonVarName ("d") 69 ## x = pyeval ("d")
62 ## @result{} x = [pyobject ...] 70 ## @result{} x = [pyobject ...]
63 ## @{'two': 2, 'one': 1@} 71 ## @{'two': 2@}
64 ## 72 ##
65 ## # oops, overwrote d in Python: 73 ## # oops, overwrote d in Python:
66 ## pyexec ("d = 42") 74 ## pyexec ("d = 42")
67 ## 75 ##
68 ## # but have no fear, we still have a reference to it: 76 ## # but have no fear, we still have a reference to it:
69 ## x 77 ## x
70 ## @result{} x = [pyobject ...] 78 ## @result{} x = [pyobject ...]
71 ## @{'two': 2, 'one': 1@} 79 ## @{'two': 2@}
72 ## @end group 80 ## @end group
73 ## @end example 81 ## @end example
74 ## 82 ##
75 ## We can accesss ``callables'' (methods) of objects: 83 ## We can accesss ``callables'' (methods) of objects:
76 ## @example 84 ## @example
77 ## @group 85 ## @group
78 ## keyslist = py.list (x.keys ()); 86 ## x.pop ("two")
79 ## keyslist.sort (); 87 ## @result{} ans = 2
80 ## keyslist
81 ## @result{} keyslist = [pyobject ...]
82 ## ['one', 'two']
83 ## @end group 88 ## @end group
84 ## @end example 89 ## @end example
90 ## And note this has changed the Python dict @code{x}:
91 ## @example
92 ## @group
93 ## x
94 ## @result{} x = [pyobject ...]
95 ## @{@}
96 ## @end group
97 ## @end example
98 ##
85 ## 99 ##
86 ## @code{pyeval} returns a @@pyobject for things it cannot convert to 100 ## @code{pyeval} returns a @@pyobject for things it cannot convert to
87 ## Octave-native objects: 101 ## Octave-native objects:
88 ## @example 102 ## @example
89 ## @group 103 ## @group
101 ## @result{} ans = ... 115 ## @result{} ans = ...
102 ## @end group 116 ## @end group
103 ## @end example 117 ## @end example
104 ## 118 ##
105 ## 119 ##
106 ## TODO: this should return a cell array with a double, a string, 120 ## A Python list is returned as a @@pyobject:
107 ## and an @@pyobject in it:
108 ## @example 121 ## @example
109 ## @group 122 ## @group
110 ## pyeval ("[42, 'hello', sys]") # doctest: +XFAIL 123 ## L = pyeval ("[42, 'hello', sys]")
124 ## @result{} L = [pyobject ...]
125 ## [42, 'hello', <module 'sys' (built-in)>]
126 ## @end group
127 ## @end example
128 ##
129 ## Elements of the list can be accessed directly
130 ## @example
131 ## @group
132 ## L@{1@}
133 ## @result{} ans = 42
134 ## @end group
135 ## @end example
136 ## or if needed, the list can be converted to a cell array:
137 ## @example
138 ## @group
139 ## cell (L)
111 ## @result{} ans = 140 ## @result{} ans =
112 ## @{ 141 ## @{
113 ## [1,1] = 42 142 ## [1,1] = 42
114 ## [1,2] = hello 143 ## [1,2] = hello
115 ## [1,3] = 144 ## = [pyobject ...]
116 ## [PyObject id ...] 145 ## <module 'sys' (built-in)>
117 ## <module 'sys' (built-in)>
118 ## @} 146 ## @}
119 ## @end group 147 ## @end group
120 ## @end example 148 ## @end example
121 ## 149 ##
122 ## A @@pyobject can be passed back to Python. This does not make 150 ## A @@pyobject can be passed back to Python. This does not make
123 ## a copy but rather a reference to the original object. 151 ## a copy but rather a reference to the original object.
124 ## For example: 152 ## For example:
125 ## @example 153 ## @example
126 ## @group 154 ## @group
127 ## pycall ("__builtin__.print", sysmodule) # doctest: +XFAIL 155 ## pycall ("repr", sysmodule)
128 ## @print{} <module 'sys' (built-in)> 156 ## @result{} <module 'sys' (built-in)>
129 ## @end group 157 ## @end group
130 ## @end example 158 ## @end example
131 ## (FIXME: I think this failure may correspond to an existing doctest issue).
132 ## 159 ##
133 ## @seealso{pyobject} 160 ## @seealso{pyobject}
134 ## @end defmethod 161 ## @end defmethod
135 162
136 function dummy (x) 163 function dummy (x)