3

In normal Python project we might have a parent py file that imports from a sibling or child folder/module (initialised by __init__.py, from .folder import module etc.

Is there a way to do this using Synapse notebooks within a given (ex. dev) workspace?

Ex. I would like to create a notebook/python module for use in logging - a wrapper to wrap functions. I don't want to have to have to copy-paste this module into 20 different notebooks.

Thanks!

Thom A
  • 88,727
  • 11
  • 45
  • 75
Paul Wilson
  • 562
  • 5
  • 16

1 Answers1

1

Yes, you can use something called notebook reference You can use %run magic command to reference another notebook within current notebook's context. All the variables defined in the reference notebook are available in the current notebook. %run magic command supports nested calls but not support recursive calls. You will receive an exception if the statement depth is larger than five.

Example: %run //Notebook1 { "parameterInt": 1, "parameterFloat": 2.5, "parameterBool": true, "parameterString": "abc" }.

Source

Aniket Kumar
  • 165
  • 2
  • 10
  • Thank you! Will read through those docs, but does this run the entire contents of the notebook? I don't want to execute the notebook, only access functions/variables from within it. (EDIT: Context here being that I might want to run a notebook to get a variable, from a notebook that is not just a "source" for variables, if that makes sense -> IE, it might be an actual notebook called in a pipeline to perform a task) – Paul Wilson Oct 13 '22 at 14:45
  • Yes, I believe you can do it. Since it is reference which is similar to import a module. – Aniket Kumar Oct 16 '22 at 02:33
  • Per my understanding, these notebooks have to be published into the live mode. My experiments proved to be a bit tricky when the team was working on multiple solution branches simultaneously. – Dan Apr 21 '23 at 22:34