Skip to content

Admin - Importing Local Modules in Quarto #35

@s2t2

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)
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions