How to load and call functions defined in a standalone Python script?

pycall

#1

Can PyCall be used to load definitions from a small Python script into Julia? For example, how can I call foo() defined in the Python script below in Julia?

a = 1
b = 2
def foo():
    print("Hello world!")
    return a + b

#2

Just do what you would have done in python

julia> using PyCall

julia> push!(pyimport("sys")["path"], pwd());

julia> pyimport("a")[:foo]()
Hello world!
3

#3

Thank you @yuyichao, I will give the solution a try. :slight_smile: