# Passing keyword arguments from a function to the other

**URL:** <https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190>\
**Category:** General Usage\
**Created:** [February 26, 2020, 6:53pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190 "2020-02-26T18:53:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 26, 2020, 6:53pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190/1 "2020-02-26T18:53:17Z")

</div>

I need to replicate the following python code, where `f1` is called with a function name, a positional argument and some keyword ones, and it passes to the function defined in its first argument the positional argument and the keyword arguments:

Python code:

```julia
def f1(fname,val,**kwargs):
    return fname(val,**kwargs)
def f2(val, kw1, kw2):
    return (val+1+kw1)/kw2
def f3(val, kw3):
    return (val+1+kw3)
f1(f2,5,kw1=4,kw2=2)
f1(f3,5,kw3=4)

```

This is what I have tried up to now, but I still have a method error:

Julia code:

```julia
function f2(val, kw1, kw2)
    return (val+1+kw1)/kw2
end
f2(val; kw1, kw2) = f2(val, kw1, kw2)
function f3(val, kw3)
    return (val+1+kw3) 
end
f3(val; kw3) = f3(val, kw3)
function f1(fname,val;kwargs...)
    return fname(val,collect(kwargs)...)
end
f1(f3,2,kw3=3)

```

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [February 26, 2020, 7:16pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190/2 "2020-02-26T19:16:23Z")

</div>

```julia
function f1(fname, val; kwargs...)
    return fname(val; kwargs...)
end

```

?

---

<div class="post-metadata">

**Author:** ![HeinBloed](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@HeinBloed](https://discourse.julialang.org/u/HeinBloed)\
**Post date:** [February 26, 2020, 7:18pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190/3 "2020-02-26T19:18:54Z")

</div>

Hi,  
the method error says that there is: no method matching +(::Int64, ::Pair{Symbol,Int64}). As your keyword kw3 is stored as a Pair. You probably want to access its second field: kw3.second

So the whole code might look like:

```julia
function f2(val, kw1, kw2)
    return (val+1+kw1)/kw2
end
f2(val; kw1, kw2) = f2(val, kw1, kw2)
function f3(val, kw3)
    return (val+1+kw3.second)
end
f3(val; kw3) = f3(val, kw3)
function f1(fname,val;kwargs...)
    return fname(val,collect(kwargs)...)
end
f1(f3,2,kw3=3)

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 27, 2020, 8:12am UTC](https://discourse.julialang.org/t/passing-keyword-arguments-from-a-function-to-the-other/35190/4 "2020-02-27T08:12:25Z")

</div>

Thank you. I wasn’t aware in using `;` in _calling_ a function.
