Variable replacement in py file

I just came into contact with jupyterlab and now I need to replace variables in the text when clicking execute. The variable list is obtained through the HTTP interface.
for example


Identified as a variable through ${}, it needs to be replaced
Now I am using the jupyterlab extension to replace the run method, but only variables in ipynb can be replaced. Variables in the referenced py file cannot be replaced yet. What should I do to replace variables in the py file ?

Maybe I’m missing something, but to replace variables in strings, you have to put a f in front of your string.
So print(f"Variable: {variable_b"}) should work if there is a such a variable in your Python file.

I’m not quite following what you are asking either, but this part sounds to me like you may want to run the script in the namespace of the active notebook, and so instead of using import you may want to use the IPython/Jupyter magic %run command and combine it with the interactive flag -i so that the code is run in the namespace. It is at least an option.

It would be something like this:

%run -i aa.py
say_hello()

After you edit say_hello to use f-strings like Paul suggests.
See more about the interactive flag for the IPython/Jupyter magic %run command here and here.