PythonCall.jl icon indicating copy to clipboard operation
PythonCall.jl copied to clipboard

Multi-line seval() in JuliaCall?

Open ArturPrzybysz opened this issue 2 years ago • 3 comments

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?

ArturPrzybysz avatar Jun 28 '23 09:06 ArturPrzybysz

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.)

cjdoris avatar Jul 04 '23 07:07 cjdoris

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] avatar Aug 19 '23 18:08 github-actions[bot]

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

github-actions[bot] avatar Aug 27 '23 01:08 github-actions[bot]