# Call an entire python script from Julia?

**URL:** https://discourse.julialang.org/t/call-an-entire-python-script-from-julia/21223
**Category:** General Usage
**Created:** [February 26, 2019, 6:01pm UTC](https://discourse.julialang.org/t/call-an-entire-python-script-from-julia/21223 "2019-02-26T18:01:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [February 26, 2019, 6:01pm UTC](https://discourse.julialang.org/t/call-an-entire-python-script-from-julia/21223/1 "2019-02-26T18:01:34Z")

</div>

```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

```

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [February 26, 2019, 6:37pm UTC](https://discourse.julialang.org/t/call-an-entire-python-script-from-julia/21223/2 "2019-02-26T18:37:08Z")

</div>

Try `py"""exec(open("calendar.py").read())"""`. (see [here](https://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3))
