Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cjdoris/pythonexec.jl
Execute Python code from Julia
https://github.com/cjdoris/pythonexec.jl
Last synced: 24 days ago
JSON representation
Execute Python code from Julia
- Host: GitHub
- URL: https://github.com/cjdoris/pythonexec.jl
- Owner: cjdoris
- License: mit
- Created: 2022-06-13T18:56:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-17T16:52:34.000Z (over 2 years ago)
- Last Synced: 2023-03-04T01:35:27.915Z (over 1 year ago)
- Language: Julia
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PythonExec.jl
Execute Python code from Julia.
## Install
```
pkg> add https://github.com/cjdoris/PythonExec.jl
```## Usage
The API mainly consists of one function `pyexec` which executes the given piece of Python
code:
```
julia> pyexec("print('hello from python')")
hello from python
```If the `ans` variable is assigned in the code, then its value will be returned:
```
julia> pyexec("ans = 1 + 2")
3
```You may specify some input variables with the `locals` argument:
```
julia> pyexec("ans = x + y", locals=(x=10, y=2))
12
```You may optionally specify a return type to override the default behaviour:
```
julia> pyexec(Symbol, "ans = 'hello'")
:hello
```Multidimensional buffers and numpy arrays are supported:
```
julia> pyexec("import numpy; ans = numpy.random.randn(2,3)")
2×3 Matrix{Float64}:
2.23817 -1.02546 0.558285
-0.901372 -0.227179 1.17542
```## Packages
By default, [CondaPkg.jl](https://github.com/cjdoris/CondaPkg.jl) is used to install Python
and any packages required. Use `CondaPkg.add()` to add any Python packages you need.