Skip to content

Admin - Importing Local Modules in Quarto #35

Description

@s2t2

FYI - here is how to load code from a shared python file into a QMD file.

Ensure there is an init file in the docs/lib dir.

Contents of the docs/lib/urls.py file:

# docs/lib/urls.py

def data_file_url():
    return "..."

Contents of the QMD file:

# docs/notes/fetching-data/json.qmd

```{python}
#| echo: false
import sys
import os

# Go up two parent directories to reach the 'docs' root folder
project_root = os.path.abspath('../..')
sys.path.insert(0, project_root)
```

```{python}
from lib.urls import data_file_url

# the URL of some JSON data we stored online:
request_url = data_file_url("gradebook.json")
print(request_url)
```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions