Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<link rel="icon" href="./favicon.ico" /> | |
<!-- Preload is necessary because we show these images when we disconnect from the server, | |
but at that point we cannot load these images from the server --> | |
<link rel="preload" href="./assets/gradient-yHQUC_QB.png" as="image" /> | |
<link rel="preload" href="./assets/noise-60BoTA8O.png" as="image" /> | |
<!-- Preload the fonts --> | |
<link rel="preload" href="./assets/Lora-VariableFont_wght-B2ootaw-.ttf" as="font" crossorigin="anonymous" /> | |
<link rel="preload" href="./assets/PTSans-Regular-CxL0S8W7.ttf" as="font" crossorigin="anonymous" /> | |
<link rel="preload" href="./assets/PTSans-Bold-D9fedIX3.ttf" as="font" crossorigin="anonymous" /> | |
<link rel="preload" href="./assets/FiraMono-Regular-BTCkDNvf.ttf" as="font" crossorigin="anonymous" /> | |
<link rel="preload" href="./assets/FiraMono-Medium-DU3aDxX5.ttf" as="font" crossorigin="anonymous" /> | |
<link rel="preload" href="./assets/FiraMono-Bold-CLVRCuM9.ttf" as="font" crossorigin="anonymous" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="theme-color" content="#000000" /> | |
<meta name="description" content="a marimo app" /> | |
<link rel="apple-touch-icon" href="./apple-touch-icon.png" /> | |
<link rel="manifest" href="./manifest.json" /> | |
<script data-marimo="true"> | |
function __resizeIframe(obj) { | |
var scrollbarHeight = 20; // Max between windows, mac, and linux | |
function setHeight() { | |
var element = obj.contentWindow.document.documentElement; | |
// If there is no vertical scrollbar, we don't need to resize the iframe | |
if (element.scrollHeight === element.clientHeight) { | |
return; | |
} | |
// Create a new height that includes the scrollbar height if it's visible | |
var hasHorizontalScrollbar = element.scrollWidth > element.clientWidth; | |
var newHeight = element.scrollHeight + (hasHorizontalScrollbar ? scrollbarHeight : 0); | |
// Only update the height if it's different from the current height | |
if (obj.style.height !== `${newHeight}px`) { | |
obj.style.height = `${newHeight}px`; | |
} | |
} | |
// Resize the iframe to the height of the content and bottom scrollbar height | |
setHeight(); | |
// Resize the iframe when the content changes | |
const resizeObserver = new ResizeObserver((entries) => { | |
setHeight(); | |
}); | |
resizeObserver.observe(obj.contentWindow.document.body); | |
} | |
</script> | |
<marimo-filename hidden>notebook.py</marimo-filename> | |
<marimo-mode data-mode='edit' hidden></marimo-mode> | |
<marimo-version data-version='0.11.9' hidden></marimo-version> | |
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"code_editor_font_size": 14, "cell_output": "above", "theme": "light", "default_width": "medium", "dataframes": "rich"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default", "overrides": {}}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun", "watcher_on_save": "lazy", "output_max_bytes": 8000000, "std_stream_max_bytes": 1000000}, "save": {"autosave": "off", "autosave_delay": 1000, "format_on_save": false}, "package_management": {"manager": "pip"}, "server": {"browser": "default", "follow_symlink": false}, "snippets": {"custom_paths": [], "include_default_snippets": true}}' data-overrides='{}' hidden></marimo-user-config> | |
<marimo-app-config data-config='{"width": "compact"}' hidden></marimo-app-config> | |
<marimo-server-token data-token='123' hidden></marimo-server-token> | |
<title>009 modules</title> | |
<script type="module" crossorigin src="./assets/index-BiV-b1K2.js"></script> | |
<link rel="stylesheet" crossorigin href="./assets/index-DkqMrX_B.css"> | |
<marimo-wasm hidden=""></marimo-wasm> | |
<script> | |
if (window.location.protocol === 'file:') { | |
alert('Warning: This file must be served by an HTTP server to function correctly.'); | |
} | |
</script> | |
<style> | |
#save-button { | |
display: none ; | |
} | |
#filename-input { | |
display: none ; | |
} | |
</style> | |
<marimo-code hidden="" data-show-code="false">import%20marimo%0A%0A__generated_with%20%3D%20%220.11.9%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%20%F0%9F%A7%A9%20Using%20modules%0A%0A%20%20%20%20%20%20%20%20A%20%60module%60%20in%20Python%20is%20a%20Python%20file%20that%20defines%20functions%20and%20variables.%20Modules%20can%20be%20%60imported%60%20into%20other%20Python%20files%2C%20letting%20you%20reuse%20their%0A%20%20%20%20%20%20%20%20functions%20and%20variables.%0A%0A%20%20%20%20%20%20%20%20We%20have%20already%20seen%20some%20modules%20in%20previous%20tutorials%2C%20including%20the%20%60math%60%0A%20%20%20%20%20%20%20%20module.%20Python%20comes%20with%20many%20other%20modules%20built-in.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20The%20Python%20standard%20library%0A%0A%20%20%20%20%20%20%20%20Python's%20%22standard%20library%22%20provides%20many%20modules%2C%20for%20many%20kinds%20of%20tasks.%0A%0A%20%20%20%20%20%20%20%20%60%60%60python%0A%20%20%20%20%20%20%20%20%23%20String%20manipulation%0A%20%20%20%20%20%20%20%20import%20string%0A%0A%20%20%20%20%20%20%20%20%23%20Operating%20system%20interactions%0A%20%20%20%20%20%20%20%20import%20os%0A%0A%20%20%20%20%20%20%20%20%23%20Date%20and%20time%20handling%0A%20%20%20%20%20%20%20%20import%20datetime%0A%0A%20%20%20%20%20%20%20%20%23%20Mathematical%20operations%0A%20%20%20%20%20%20%20%20import%20math%0A%20%20%20%20%20%20%20%20%60%60%60%0A%0A%20%20%20%20%20%20%20%20See%20the%20%5BPython%20standard%20library%20documentation%5D(https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2F)%20for%20a%20full%20reference%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%23%23%23%20Example%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20string%0A%20%20%20%20import%20os%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20math%0A%0A%20%20%20%20%23%20Example%20of%20using%20imported%20modules%0A%20%20%20%20def%20demonstrate_standard_library_usage()%3A%0A%20%20%20%20%20%20%20%20%23%20String%20module%3A%20get%20all%20punctuation%0A%20%20%20%20%20%20%20%20punctuation_example%20%3D%20string.punctuation%0A%0A%20%20%20%20%20%20%20%20%23%20OS%20module%3A%20get%20current%20working%20directory%0A%20%20%20%20%20%20%20%20current_dir%20%3D%20os.getcwd()%0A%0A%20%20%20%20%20%20%20%20%23%20Datetime%20module%3A%20get%20current%20date%0A%20%20%20%20%20%20%20%20today%20%3D%20datetime.date.today()%0A%0A%20%20%20%20%20%20%20%20%23%20Math%20module%3A%20calculate%20square%20root%0A%20%20%20%20%20%20%20%20sqrt_example%20%3D%20math.sqrt(16)%0A%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Punctuation%22%3A%20punctuation_example%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Current%20Directory%22%3A%20current_dir%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Today's%20Date%22%3A%20today%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Square%20Root%20Example%22%3A%20sqrt_example%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%23%20Run%20the%20demonstration%0A%20%20%20%20module_usage_examples%20%3D%20demonstrate_standard_library_usage()%0A%20%20%20%20module_usage_examples%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20datetime%2C%0A%20%20%20%20%20%20%20%20demonstrate_standard_library_usage%2C%0A%20%20%20%20%20%20%20%20math%2C%0A%20%20%20%20%20%20%20%20module_usage_examples%2C%0A%20%20%20%20%20%20%20%20os%2C%0A%20%20%20%20%20%20%20%20string%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Import%20syntax%0A%0A%20%20%20%20%20%20%20%20You%20can%20import%20entire%20modules%2C%20and%20access%20their%20functions%20and%20variables%20using%20dot%20notation%20(%60math.sqrt%60).%20Or%20you%20can%20import%20specific%20members%3A%0A%0A%20%20%20%20%20%20%20%20%60%60%60python%0A%20%20%20%20%20%20%20%20%23%20Import%20entire%20module%0A%20%20%20%20%20%20%20%20import%20math%0A%0A%20%20%20%20%20%20%20%20%23%20Import%20specific%20functions%0A%20%20%20%20%20%20%20%20from%20math%20import%20sqrt%2C%20pow%0A%0A%20%20%20%20%20%20%20%20%23%20Import%20with%20alias%0A%20%20%20%20%20%20%20%20import%20math%20as%20m%0A%20%20%20%20%20%20%20%20%60%60%60%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20demonstrate_import_strategies()%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Demonstrate%20different%20import%20strategies%20using%20the%20math%20module%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Strategy%201%3A%20Import%20entire%20module%0A%20%20%20%20%20%20%20%20import%20math%0A%20%20%20%20%20%20%20%20entire_module_result%20%3D%20math.sqrt(25)%0A%0A%20%20%20%20%20%20%20%20%23%20Strategy%202%3A%20Import%20specific%20functions%0A%20%20%20%20%20%20%20%20from%20math%20import%20pow%2C%20sqrt%0A%20%20%20%20%20%20%20%20specific_import_result%20%3D%20pow(2%2C%203)%0A%0A%20%20%20%20%20%20%20%20%23%20Strategy%203%3A%20Import%20with%20alias%0A%20%20%20%20%20%20%20%20import%20math%20as%20m%0A%20%20%20%20%20%20%20%20alias_result%20%3D%20m.sqrt(16)%0A%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Entire%20Module%20Import%22%3A%20entire_module_result%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Specific%20Function%20Import%22%3A%20specific_import_result%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Alias%20Import%22%3A%20alias_result%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%23%20Run%20the%20import%20strategy%20demonstration%0A%20%20%20%20import_strategy_examples%20%3D%20demonstrate_import_strategies()%0A%20%20%20%20import_strategy_examples%0A%20%20%20%20return%20demonstrate_import_strategies%2C%20import_strategy_examples%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Third-party%20packages%0A%0A%20%20%20%20%20%20%20%20In%20addition%20to%20Python's%20standard%20library%2C%20there%20are%20hundreds%20of%20thousands%20of%0A%20%20%20%20%20%20%20%20modules%20available%20for%20free%20on%20the%20Python%20Package%20index.%0A%0A%20%20%20%20%20%20%20%20These%20are%20distributed%20as%20Python%20%22packages%22%2C%20and%20include%20packages%20for%0A%20%20%20%20%20%20%20%20manipulating%20arrays%20of%20numbers%2C%20creating%20web%20applications%2C%20and%20more.%20%60marimo%60%0A%20%20%20%20%20%20%20%20itself%20is%20a%20third-party%20package!%0A%0A%20%20%20%20%20%20%20%20For%20installing%20packages%20on%20your%20machine%2C%20we%20recommend%20using%20the%20%5B%60uv%60%20package%20manager%5D(https%3A%2F%2Fdocs.astral.sh%2Fuv%2F).%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A</marimo-code></head> | |
<body> | |
<div id="root"></div> | |
</body> | |
</html> | |