How to get a variable by its name?

This simple problem may sound silly but I can not find any solution on the internet.
I wanna wrap a model in a class.

In method 1:

with pm.model() as self.model:
    a = pm.Normal()

In method 2:

with self.model:
    a # How can I access a?

I know I can make a as self.a, but do we have other ways?

You can access it from model.named_vars, which is a dictionary with RV name and RV pair.

1 Like

Oh sorry. I read the document of Model but didn’t notice this. Thanks!