Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active December 26, 2023 18:34
Show Gist options
  • Save fomightez/7e9424e531dfb01bc6f903728bc0ff2e to your computer and use it in GitHub Desktop.
Save fomightez/7e9424e531dfb01bc6f903728bc0ff2e to your computer and use it in GitHub Desktop.
`.ipynb` file illustrating Use of reload to by pass default import handling for SO https://stackoverflow.com/a/77718555/8508004
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "4872f210-c0b0-4b91-b74e-5f6d58dfbd7d",
"metadata": {},
"source": [
"### Use of reload to by pass default import handling\n",
"\n",
"See [Jupyter Notebook Reload Module: A Guide\n",
"](https://saturncloud.io/blog/jupyter-notebook-reload-module-a-comprehensive-guide/) and [here](https://stackoverflow.com/questions/52400814/reload-python-module-within-jupyter-notebook-without-autoreload#comment103213700_52401315), especially the comment about what you do in modern Python 3.\n",
"\n",
"Illustrating the option without the magic command.\n",
"\n",
"You can just add a separate cell with two additional lines in between the two cells you mention. \n",
"Or add it to the top of the second cell. This illustrates that latter option."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cfae5104-6b93-4133-8edc-8e2001e68126",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:root:debug1abc\n",
"INFO:root:info1abc\n",
"WARNING:root:warning1abc\n",
"ERROR:root:error1abc\n",
"CRITICAL:root:critical1abc\n"
]
}
],
"source": [
"import logging\n",
"logging.basicConfig(level=logging.DEBUG)\n",
"\n",
"logging.debug(\"debug1abc\")\n",
"logging.info(\"info1abc\")\n",
"logging.warning(\"warning1abc\")\n",
"logging.error(\"error1abc\")\n",
"logging.critical(\"critical1abc\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0c0d42c8-2943-4777-8958-68b16d234978",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:warning1xyz\n",
"ERROR:root:error1xyz\n",
"CRITICAL:root:critical1xyz\n"
]
}
],
"source": [
"import importlib\n",
"importlib.reload(logging)\n",
"import logging\n",
"\n",
"logging.debug(\"debug1xyz\")\n",
"logging.info(\"info1xyz\")\n",
"logging.warning(\"warning1xyz\")\n",
"logging.error(\"error1xyz\")\n",
"logging.critical(\"critical1xyz\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b605f86-2f5f-413e-8467-c47734290e86",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment