Skip to content

Commit 008074f

Browse files
author
Christopher Doris
committed
add seval example [skip ci]
1 parent 110758e commit 008074f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/src/juliacall.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,21 @@ In this example:
4646
If you are writing a package which uses Julia, then to avoid polluting the global `Main`
4747
namespace you instead should start with:
4848
```python
49-
import juliacall; jl = juliacall.newmodule("SomeName");
49+
import juliacall
50+
jl = juliacall.newmodule("SomeName")
51+
```
52+
53+
Julia modules have a special method `seval` which will evaluate a given piece of code given
54+
as a string in the module. This is most frequently used to import modules:
55+
```python
56+
from array import array
57+
jl.seval("using Statistics")
58+
x = array('i', [1, 2, 3])
59+
jl.mean(x)
60+
# 2.0
61+
y = array('i', [2,4,8])
62+
jl.cor(x, y)
63+
# 0.9819805060619657
5064
```
5165

5266
What to read next:

0 commit comments

Comments
 (0)