How can we share useful functions between demonstration notebooks when I want them to be self contained?

Aperta
#263 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@DavidT3 ci sta già lavorando.

Dal 13/5/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

doc-infrastructure

Usually if I wanted to share functions between notebooks I'd make some common.py file and add it to the system path e.g. (ripped from one of my research notebook repos):

import pandas as pd
pd.set_option('display.max_columns', 500)
import numpy as np
from astropy.units import Quantity
from astropy.cosmology import LambdaCDM
import os

# This adds the directory above to the path, allowing me to import the common functions that I've written in
#  common.py - this just saves me repeating boring code and makes sure its all consistent
import sys
sys.path.insert(0, '..')
from common import xcs_cosmo, lx_norm, m_norm

import xga
from xga.relations.fit import scaling_relation_lira

However, I specifically diverged from how the Fornax notebooks work (and I think how IRSA does it) and don't use files to declare functions, instead they are defined in a collapsed section of the notebook.

Great, other than when we want multiple notebooks to have the same functions - then we have to maintain them in multiple places.

I don't have a good solution for this yet, other than post-processing the notebooks with a github action to replace any declarations of a commonly-named function when it changes in some centralized file where it is maintained?

Lingua principale
Python
Stelle
6
Fork
3
Merge medio
23h 20m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di heasarc/heasarc-tutorials

Tutte le issue di heasarc/heasarc-tutorials

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.