# Using dot syntax and Symbols from Python

**URL:** <https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368>\
**Category:** General Usage\
**Tags:** juliacall, pyjulia\
**Created:** [February 13, 2022, 7:30pm UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368 "2022-02-13T19:30:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Post date:** [February 13, 2022, 7:30pm UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368/1 "2022-02-13T19:30:00Z")

</div>

Is there a convenient way to use functions that make use of the dot syntax, as well as `Symbol`s using `juliacall` (or alternatively `pyjulia`)?

(Example code utilizing `JuMP`, after `from juliacall import Main as jl`) I know I can do:

```julia
# python code:
jl.seval("JuMP.value.(model.ext[:myvariable])")

```

This is rather non-elegant, and I can’t find out how to call the broadcasted version of `JuMP.value`?!

Ideally I am looking to do something similar like calling `...!` functions (via `..._b`), like:

```julia
# python code:
myvariable = jl.seval(":myvariable")
v = jl.JuMP.value_d(model.ext[myvariable])

```

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [February 14, 2022, 12:58am UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368/2 "2022-02-14T00:58:22Z")

</div>

You can do this:

```python
In [21]: from juliacall import Main as jl

In [22]: jl.seval("using JuMP")

In [23]: JuMp = jl.seval("JuMP")

In [24]: JuMp.value # TAB completion works
Out[24]: value (generic function with 15 methods)

In [26]: jl.seval("struct B x end")

In [27]: B = jl.seval("B")

In [28]: b = B(2)

In [29]: b.x # TAB completion works in ipython
Out[29]: 2

```

In juliacall Julia modules are available in Python as instances of `juliacall.ModuleValue`. They are not really Python types or classes.

On the other hand, pyjulia (the `julia` module) makes Python modules out of Julia modules:

```python
In [13]: from julia import JuMP

In [14]: JuMP.value
Out[14]: <PyCall.jlwrap value>

# JuliaModule is a subclass of the Python class (or type) ModuleType

In [15]: type(JuMP)
Out[15]: julia.core.JuliaModule

In [16]: from types import ModuleType

In [17]: isinstance(JuMP, ModuleType)
Out[17]: True

```

---

<div class="post-metadata">

**Author:** ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Post date:** [February 14, 2022, 8:06am UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368/3 "2022-02-14T08:06:06Z")

</div>

> [@jlapeyre](#):
>
> In juliacall Julia modules are available in Python as instances of `juliacall.ModuleValue` . They are not really Python types or classes.

I am not really sure why that would be a disadvantage in my case?

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [February 14, 2022, 12:30pm UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368/4 "2022-02-14T12:30:09Z")

</div>

I don’t think it’s a necessarily a disadvantage. They both allow you to use dots, but in terms of the Python types, they are very different. I don’t know if one is better than the other or why.

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [February 14, 2022, 2:52pm UTC](https://discourse.julialang.org/t/using-dot-syntax-and-symbols-from-python/76368/5 "2022-02-14T14:52:56Z")

</div>

> [@sstroemer](#):
>
> This is rather non-elegant, and I can’t find out how to call the broadcasted version of `JuMP.value` ?!

I’d use `seval` to create an anonymous function to do the broadcasting, like so:

```julia
f = jl.seval("x->JuMP.value.(x)")
v = jl.Symbol("myvariable")
f(model.ext[v])

```

This way the function `f` (and symbol `v`) can be computed once, but called many times.

Creating an anonymous function like this is a good way to access Julia semantics (such as broadcasting or macros) not otherwise exposed by JuliaCall.
