0

I am trying to programmatically find all Python multiline strings defined in a Jupyter notebook, and then to find and replace their contents.

Is my best option to do this to parse the notebook using nbconvert and then to find the strings using `ast?

RoyalTS
  • 9,545
  • 12
  • 60
  • 101
  • Just spitballing a different approach...I'd run a notebook check what my defined strings were among globals and then issue `%run .ipynb` to run the notebook in the same namespace. Then check what strings added and which are multiline. Then with those collected, you should be able to run the notebook I'd suggest then using nbformat to iterate over the notebook parts and act on the appropriate parts. Similar to what I just suggested [here](https://stackoverflow.com/questions/74460230/modify-jupiter-notebooknbformat-from-code-specifically-replace#comment131454556_74460230). – Wayne Nov 16 '22 at 19:59
  • Or if you assigning of the strings in the target notebooks is consistent enough you could just use nbformat to iterate over the notebook file and detect the presence of `\n` and replace those? – Wayne Nov 16 '22 at 20:00

0 Answers0