# Question on Warning: \`getindex(o::PyObject, s::AbstractString)\` is deprecated in favor of dot overloading

**URL:** <https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703>\
**Category:** New to Julia\
**Tags:** question, plotting, pyplot\
**Created:** [May 18, 2020, 4:48pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703 "2020-05-18T16:48:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)\
**Post date:** [May 18, 2020, 4:48pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/1 "2020-05-18T16:48:06Z")

</div>

I want to modify rcParams by

```julia
rcParams = PyDict(matplotlib["rcParams"])
rcParams["text.usetex"] = true;
rcParams["text.latex.preamble"] = raw"\usepackage{{amsmath}}";

```

but I get the getindex warning. How do I fix that warning? Just

```julia
rcParams = PyDict(matplotlib["rcParams"])
rcParams.text.usetex = true;
rcParams,text.latex.preamble = raw"\usepackage{{amsmath}}";

```

does not work…

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 18, 2020, 7:05pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/2 "2020-05-18T19:05:48Z")

</div>

> [@janrpeters](#):
>
> rcParams,text

You have a comma `,` instead of a dot `.` there.

If that doesn’t fix the issue, please post the _full_ error output you get, including the stack trace. Otherwise it’s very hard to tell what’s wrong and therefore very hard to help you.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 18, 2020, 8:38pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/3 "2020-05-18T20:38:14Z")

</div>

> [@janrpeters](#):
>
> `PyDict(matplotlib["rcParams"])`

Use `PyDict(matplotlib."rcParams")`, as the deprecation message suggests.

Also, I think you want `rcParams["text.latex.preamble"] = raw"\usepackage{amsmath}"` … the `{{...}}` double braces are an [escaping technique from Python](https://docs.python.org/3.3/library/string.html#format-string-syntax), where `{...}` has a special meaning in a string (unlike Julia).

i.e.

```julia
using PyCall, PyPlot
rcParams = PyDict(matplotlib."rcParams")
rcParams["text.usetex"] = true
rcParams["text.latex.preamble"] = raw"\usepackage{amsmath}"

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 18, 2020, 8:40pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/4 "2020-05-18T20:40:02Z")

</div>

Also, `text.usetex` is not an attribute, nor is it nested attributes. It is a key in the `dict` and the current way to set/get it is via `set!`/`get`.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 18, 2020, 8:42pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/5 "2020-05-18T20:42:31Z")

</div>

> [@janrpeters](#):
>
> rcParams[“text.usetex”] = true;

Also, are you sure this works? I think it is setting the `text.usetex` attribute on the `dict` and not the corresponding key.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 18, 2020, 8:45pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/7 "2020-05-18T20:45:02Z")

</div>

> [@yuyichao](#):
>
> Also, are you sure this works? I think it is setting the `text.usetex` attribute on the `dict` and not the corresponding key.

Yes, I think that is what is intended here. The [Matplotlib rcparams](https://matplotlib.org/3.2.1/tutorials/introductory/customizing.html) keys are strings with their own dot-structured hierarchy, and `rcParams["text.usetex"]` is indeed [a correct key](https://matplotlib.org/tutorials/text/usetex.html).

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 18, 2020, 8:48pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/8 "2020-05-18T20:48:06Z")

</div>

Ah, OK, `PyDict` is the wrapper that does the right thing with `get/setindex` already. Personally I’ve been using the `update` method instead before the default `setindex!` does the right thing…

---

<div class="post-metadata">

**Author:** ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)\
**Post date:** [May 19, 2020, 11:44am UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/9 "2020-05-19T11:44:57Z")

</div>

Sorry, a stupid question: What is the `update` method?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 19, 2020, 1:13pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/10 "2020-05-19T13:13:41Z")

</div>

[Built-in Types — Python 3.10.6 documentation](https://docs.python.org/3/library/stdtypes.html#dict.update) . `PyDict` is fine.

---

<div class="post-metadata">

**Author:** ![janrpeters](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@janrpeters](https://discourse.julialang.org/u/janrpeters)\
**Post date:** [May 19, 2020, 2:13pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/11 "2020-05-19T14:13:15Z")

</div>

That’s a Python command, right? Interesting!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 21, 2020, 6:13pm UTC](https://discourse.julialang.org/t/question-on-warning-getindex-o-pyobject-s-abstractstring-is-deprecated-in-favor-of-dot-overloading/39703/12 "2020-05-21T18:13:53Z")

</div>

Yes, and that was the point. The python side currently has a more stable API. And as I said, I didn’t realize `PyDict` does this in the “final API” form. It should be fine. (Though I do feel like it will also subject to deprecation since I don’t really see why it’ll still be needed after the `PyObject` get the same API…)
