@@ -145,45 +145,45 @@ which is automatically converted to a Julia type, you will have override this
145
145
via ` @pywith EXPR::PyObject ... ` .
146
146
147
147
If you are already familiar with Python, it perhaps is easier to use
148
- ` py" ..." ` and ` py""" ...""" ` which are equivalent to Python's
148
+ ` py\ ` ...\` ` and ` py\ ` \`\` ...\`\`\` ` which are equivalent to Python's
149
149
[ ` eval ` ] ( https://docs.python.org/3/library/functions.html#eval ) and
150
150
[ ` exec ` ] ( https://docs.python.org/3/library/functions.html#exec ) ,
151
151
respectively:
152
152
153
153
``` julia
154
- py """
154
+ py\ ` \`\`
155
155
import numpy as np
156
156
157
157
def sinpi(x):
158
158
return np.sin(np.pi * x)
159
- """
160
- py " sinpi" (1 )
159
+ \`\`\`
160
+ py\` sinpi\` (1)
161
161
` ``
162
162
163
163
When creating a Julia module , it is a useful pattern to define Python
164
164
functions or classes in Julia' s ` __init__` and then use it in Julia
165
- function with ` py" ..." ` .
165
+ function with ` py\` ...\` ` .
166
166
167
167
``` julia
168
168
module MyModule
169
169
170
170
using PyCall
171
171
172
172
function __init__()
173
- py """
173
+ py\`\`\`
174
174
import numpy as np
175
175
176
176
def one(x):
177
177
return np.sin(x) ** 2 + np.cos(x) ** 2
178
- """
178
+ \`\`\`
179
179
end
180
180
181
- two (x) = py " one" (x) + py " one" (x)
181
+ two(x) = py\` one\` (x) + py\` one\` (x)
182
182
183
183
end
184
184
```
185
185
186
- Note that Python code in ` py" ..." ` of above example is evaluated in a
186
+ Note that Python code in ` py\` ...\` ` of above example is evaluated in a
187
187
Python namespace dedicated to ` MyModule` . Thus, Python function ` one`
188
188
cannot be accessed outside ` MyModule` .
189
189
@@ -355,38 +355,38 @@ and also by providing more type information to the Julia compiler.
355
355
` @pycall function(args...)::returntype` into
356
356
` pycall(function,returntype,args...)` .
357
357
358
- * ` py" ..." ` evaluates ` "..." ` as Python code, equivalent to
358
+ * ` py\` ...\` ` evaluates ` "..."` as Python code, equivalent to
359
359
Python' s [` eval` ](https: // docs. python. org/ 3 / library/ functions. html# eval) function, and returns the result
360
- converted to ` PyAny ` . Alternatively, ` py" ..." o ` returns the raw ` PyObject `
360
+ converted to ` PyAny` . Alternatively, ` py\` ...\` o` returns the raw ` PyObject`
361
361
(which can then be manually converted if desired). You can interpolate
362
362
Julia variables and other expressions into the Python code with ` $` ,
363
363
which interpolates the * value* (converted to ` PyObject` ) of the given
364
364
expression--- data is not passed as a string, so this is different from
365
- ordinary Julia string interpolation. e.g. ` py" sum($([1,2,3]))" ` calls the
365
+ ordinary Julia string interpolation. e. g. ` py\` sum($([1 ,2 ,3 ]) )\` ` calls the
366
366
Python ` sum` function on the Julia array ` [1,2,3]` , returning ` 6` .
367
367
In contrast, if you use ` $$` before the interpolated expression, then
368
368
the value of the expression is inserted as a string into the Python code,
369
369
allowing you to generate Python code itself via Julia expressions.
370
- For example, if ` x="1+1" ` in Julia, then ` py"$x" ` returns the string ` "1+1" ` ,
371
- but ` py" $$x" ` returns ` 2 ` .
372
- If you use ` py""" ...""" ` to pass a * multi-line* string, the string can
370
+ For example, if ` x="1+1"` in Julia, then ` py\` $x \` ` returns the string ` "1+1"` ,
371
+ but ` py\` $$x \` ` returns ` 2` .
372
+ If you use ` py\`\`\` ...\`\`\` ` to pass a * multi- line* string, the string can
373
373
contain arbitrary Python code (not just a single expression) to be evaluated,
374
374
but the return value is ` nothing` ; this is useful e. g. to define pure- Python
375
375
functions, and is equivalent to Python' s
376
376
[` exec` ](https: // docs. python. org/ 3 / library/ functions. html# exec) function.
377
- (If you define a Python global ` g ` in a multiline ` py""" ...""" `
378
- string, you can retrieve it in Julia by subsequently evaluating ` py"g" ` .)
377
+ (If you define a Python global ` g` in a multiline ` py\`\`\` ...\`\`\` `
378
+ string, you can retrieve it in Julia by subsequently evaluating ` py\` g \` ` .)
379
379
380
- When ` py" ..." ` is used inside a Julia module, it uses a Python namespace
380
+ When ` py\` ...\` ` is used inside a Julia module , it uses a Python namespace
381
381
dedicated to this Julia module . Thus, you can define Python function
382
- using ` py""" ....""" ` in your module without worrying about name clash
382
+ using ` py\`\`\` ....\`\`\` ` in your module without worrying about name clash
383
383
with other Python code. Note that Python functions _must_ be defined in
384
384
` __init__` . Side- effect in Python occurred at top- level Julia scope
385
385
cannot be used at run- time for precompiled modules.
386
386
387
387
* ` pybuiltin(s)` : Look up ` s` (a string or symbol) among the global Python
388
388
builtins. If ` s` is a string it returns a ` PyObject` , while if ` s` is a
389
- symbol it returns the builtin converted to ` PyAny ` . (You can also use ` py"s" `
389
+ symbol it returns the builtin converted to ` PyAny` . (You can also use ` py\` s \` `
390
390
to look up builtins or other Python globas.)
391
391
392
392
Occasionally, you may need to pass a keyword argument to Python that
0 commit comments