You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Bringing [**Python®**](https://www.python.org/) and [**Julia**](https://juliala
14
14
- Fast non-copying conversion of numeric arrays in either direction: modify Python arrays (e.g. `bytes`, `array.array`, `numpy.ndarray`) from Julia or Julia arrays from Python.
15
15
- Helpful wrappers: interpret Python sequences, dictionaries, arrays, dataframes and IO streams as their Julia counterparts, and vice versa.
16
16
- Beautiful stack-traces.
17
-
- Supports modern systems: tested on Windows, MacOS and Linux, 64-bit, Julia 1.9 upwards and Python 3.9 upwards.
17
+
- Supports modern systems: tested on Windows, MacOS and Linux, 64-bit, Julia 1.10 upwards and Python 3.10 upwards.
18
18
19
19
⭐ If you like this, a GitHub star would be lovely thank you. ⭐
Copy file name to clipboardExpand all lines: docs/src/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,4 +7,4 @@ Bringing [**Python®**](https://www.python.org/) and [**Julia**](https://juliala
7
7
- Fast non-copying conversion of numeric arrays in either direction: modify Python arrays (e.g. `bytes`, `array.array`, `numpy.ndarray`) from Julia or Julia arrays from Python.
8
8
- Helpful wrappers: interpret Python sequences, dictionaries, arrays, dataframes and IO streams as their Julia counterparts, and vice versa.
9
9
- Beautiful stack-traces.
10
-
- Works anywhere: tested on Windows, MacOS and Linux, 32- and 64-bit, Julia Julia 1.9 upwards and Python 3.9 upwards.
10
+
- Works anywhere: tested on Windows, MacOS and Linux, 32- and 64-bit, Julia Julia 1.10 upwards and Python 3.10 upwards.
With the functions introduced so far, you have access to the vast majority of Python's
92
92
functionality.
93
93
94
+
## Executing Python scripts
95
+
96
+
A common use case is calling multiple blocks of Python code from Julia interactively. This can be accomplished in PythonCall via the [@pyexec](@ref) macro. For example, the sentence parsing application in the [Getting started](@ref py_getting_started) section could be rewritten as:
97
+
98
+
```julia-repl
99
+
julia> @pyexec """
100
+
global re
101
+
import re
102
+
103
+
def my_sentence(s):
104
+
words = re.findall("[a-zA-Z]+", s)
105
+
sentence = " ".join(words)
106
+
return sentence
107
+
""" => my_sentence
108
+
Python: <function my_sentence at 0x7d83bb1b01a0>
109
+
110
+
julia> sentence = my_sentence("PythonCall.jl is very useful!")
111
+
Python: 'PythonCall jl is very useful'
112
+
```
113
+
114
+
Note the use of the `global` keyword to make the `re` package accessible in global scope, and the `=> my_sentence` syntax to create a Julia function named `my_sentence` that calls to the Python function of the same name. This syntax also supports calling to multiple functions and passing data back-and-forth:
115
+
116
+
```julia-repl
117
+
julia> @pyexec (num=10) => """
118
+
def add(a, b):
119
+
return a + b
120
+
121
+
def subtract(a, b):
122
+
return a - b
123
+
124
+
plusone = num + 1
125
+
""" => (add, subtract, plusone::Float64)
126
+
(add = <py function add at 0x721b001a7cc0>, subtract = <py function subtract at 0x721b001a7d70>, plusone = 11.0)
127
+
128
+
julia> add(4, 3)
129
+
Python: 7
130
+
131
+
julia> subtract(4, 3)
132
+
Python: 1
133
+
134
+
julia> plusone
135
+
11.0
136
+
```
137
+
138
+
Here we demonstrate passing a named variable, `num`, via the use of the `=>` syntax again, and returning named output, with the last element, `plusone`, being cast to a Julia object via the `::` syntax. See [@pyexec](@ref), [@pyeval](@ref), and their functional forms [pyexec](@ref) and [pyeval](@ref), for more.
139
+
94
140
## Conversion between Julia and Python
95
141
96
142
A Julia object can be converted to a Python one either explicitly (such as `Py(x)`) or
@@ -369,6 +415,10 @@ See [Installing Python packages](@ref python-deps).
369
415
370
416
## [Multi-threading](@id jl-multi-threading)
371
417
418
+
!!! warning
419
+
420
+
Multi-threading support is experimental and can change without notice.
421
+
372
422
From v0.9.22, PythonCall supports multi-threading in Julia and/or Python, with some
0 commit comments