JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
776 stars 63 forks source link

Multi-line seval() in JuliaCall? #331

Open ArturPrzybysz opened 1 year ago

ArturPrzybysz commented 1 year ago

Hi, I want to run Julia script from Python code. The only way I know how to achieve this is by:

    with open("my_cuda_script.jl") as f:
        jl_code_lines = f.readlines()

    for line in jl_code_lines:
        out = jl.seval(line)
    print(out)

Clearly, this is not an ideal setup and likely adds unnecessary overhead.

How can I run the whole script, or more generally Julia code string with many lines, all at once?

cjdoris commented 1 year ago

Just wrap the code in a begin-end block, e.g.:

    with open("my_cuda_script.jl") as f:
        jl_code = f.read()

    out = jl.seval(f'begin\n{jl_code}\nend')

(I suppose this is something that seval could do for you.)

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has been open for 30 days with no activity. If the issue is still relevant then please leave a comment, or else it will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue has been closed because it has been stale for 7 days. You can re-open it if it is still relevant.