Runnable Python module (Python 3 )
Runnable Python module
When we import a module, its name (stored in the variable
__name__) is equal to the module name. When a script is executed, its name is always set to the
Hence, if we check for this name with
if __name__ == '__main__' we can detect if we are running as a script or if we're being included somewhere as a module.
I created a simple module in the following code crumb that does this check. Because we don't import this file but run it directly, the function is executed and we see something printed to our screen. However, if you would import this module, the function would not be called.
This example is from my articles on Python modules. Click to learn more about modules and packages.
Edit and run this Python 3 example code
This code is editable and runnable. You can run "Runnable Python module" by pressing the run button.
It will be executed in our backend and the result (
stderr) is displayed
in addition tabs.
Share "Runnable Python module"
Share this crumb (Runnable Python module) with your friends and colleagues to help them learn more about Python 3 programming.
Twitter, Facebook, LinkedIn
On Twitter, Facebook, and LinkedIn, simply paste the URL in your post and watch the magic unfold.
If you want to embed the crumb in an iframe, use the following code:
We support oEmbed, but most sites use allowlisting. On WordPress, oEmbed is supported out of the box, but see the note below.
If you plan to use crumb.sh heavily on Wordpress, you can use the following PHP code to allowlist our site and
unlock all the functionalities of our crumbs:
wp_oembed_add_provider( 'https://crumb.sh/*', 'https://crumb.sh/oembed/' );
Embed.ly is a service that allows you to embed content from other sites. We will request to be added to the list of trusted sites once we're out of beta.