In a notebook, do the following in a cell:
%pip install jupytext
!jupytext --to notebook <name_of_script_file>.py
Replacing <name_of_script_file>
with name of your Python script. You may need to specify the path if your working directory in the notebook and where the script is aren’t the same.
Or you could use the terminal to run jupytext if you comfortable. The magic install though insures it will work in whatever environment that notebook happened to be running in.
See here for more about Jupytext use.
There’s also the use of the %load
command that may do what you require?
See here and here.