Calling Python

The PyCall package provides us with the ability to call Python from Julia code. As always, add this package to your Julia environment with add PyCall. Then, you can start using it in the REPL, or in a script as follows:

using PyCall 
py"10*10"             #> 100 
@pyimport math 
math.sin(math.pi / 2) #> 1.0 

As we can see with the @pyimport macro, we can easily import any Python library; functions inside such a library are called with the familiar dot notation.

For more details, refer to https://github.com/stevengj/PyCall.jl.

Get Julia 1.0 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.