Call an entire python script from Julia?

shell > cat calendar.py
# Python program to display calendar of given month of the year

# import module
import calendar

yy = 2014
mm = 11

# To ask month and year from the user
# yy = int(input("Enter year: "))
# mm = int(input("Enter month: "))

# display the calendar
print(calendar.month(yy, mm))

julia > pyeval("execfile(x)", x="calendar.py")
┌ Warning: pyeval is deprecated.  Use py"execfile(x)" instead.  Use $ interpolation to substitute Julia variables and expressions into Python.
│   caller = ip:0x0
└ @ Core :-1
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/devel/.julia/packages/PyCall/0jMpb/src/pyeval.jl:23 =# @pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPtr, PyPtr), o, globals, locals))))) <class 'NameError'>
NameError("name 'execfile' is not defined")
  File "PyCall", line 1, in <module>

Stacktrace:
 [1] pyerr_check at /home/devel/.julia/packages/PyCall/0jMpb/src/exception.jl:60 [inlined]
 [2] pyerr_check at /home/devel/.julia/packages/PyCall/0jMpb/src/exception.jl:64 [inlined]
 [3] macro expansion at /home/devel/.julia/packages/PyCall/0jMpb/src/exception.jl:85 [inlined]
 [4] pyeval_(::String, ::PyDict{String,PyObject,false}, ::PyDict{AbstractString,PyObject,true}, ::Int64, ::String) at /home/devel/.julia/packages/PyCall/0jMpb/src/pyeval.jl:20
 [5] pyeval_ at /home/devel/.julia/packages/PyCall/0jMpb/src/pyeval.jl:17 [inlined]
 [6] #pyeval#90(::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol},NamedTuple{(:x,),Tuple{String}}}, ::Function, ::String, ::Type{PyAny}, ::PyDict{AbstractString,PyObject,true}, ::Int64) at /home/devel/.julia/packages/PyCall/0jMpb/src/pyeval.jl:63
 [7] #pyeval at ./none:0 [inlined] (repeats 2 times)
 [8] top-level scope at none:0

Try py"""exec(open("calendar.py").read())""". (see here)

1 Like