7

I am working on the Kaggle HuBMAP competition. My application consists of several components -- Preprocessing, Training, Prediction and Scoring -- and there is common code that is used by more than one component. Currently, I put multiple copies of the common code in the Notebooks for each of the components, but I'd like to maintain one copy of the common code that I can import into my application components.

My question is: Where do I store that common code so that it can be imported? Does it go in a separate DataSet? Or a separate Notebook? How do I store it? How do I import it?

1 Answer 1

7

Figured out how to do it:

  1. Create a file like common_code.py to hold the code you want to import in Kaggle
  2. Create a Kaggle DataSet like CommonCode and upload common_code.py to it
  3. In the Notebook where you want to import the common code add the DataSet CommonCode
  4. At the top of your Notebook, add the following code:
import sys sys.path.append( "/kaggle/input/CommonCode" ) 

Then, at any subsequent point in the Notebook you can say

from common_code import * 

While this shows an example of a single import-able file, you can use it for any number of files, and you can update the DataSet for additions or revisions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.