Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define python function from Julia side #156

Closed
chengchingwen opened this issue Apr 14, 2022 · 3 comments
Closed

How to define python function from Julia side #156

chengchingwen opened this issue Apr 14, 2022 · 3 comments

Comments

@chengchingwen
Copy link

Is there any way to define python function from Julia side? or something equivalent to PyCall.@py_strthat can run arbitrary python code from Julia?

@icweaver
Copy link

I had a similar question a little bit ago, and I think the main takeaway was to just do something like this:

julia> using PythonCall

julia> @pyexec """
       global double
       def double(s):
           return s * 2
       """
julia> double(s) = @pyeval("double")(s)
double (generic function with 1 method)

julia> double("hello")
Python str: 'hellohello'

@chengchingwen
Copy link
Author

Great, thanks!

@CarloLucibello
Copy link
Contributor

This is a bit hard to discover, it should be given more prominence in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants