diff --git a/run-python-scripts/README.md b/run-python-scripts/README.md new file mode 100644 index 0000000000..e6ad64ee92 --- /dev/null +++ b/run-python-scripts/README.md @@ -0,0 +1,3 @@ +# How to Run Your Python Scripts and Code + +This folder provides the code examples for the Real Python tutorial [How to Run Your Python Scripts and Code](https://realpython.com/run-python-scripts/). diff --git a/run-python-scripts/hello.py b/run-python-scripts/hello.py new file mode 100644 index 0000000000..6e108ce1a0 --- /dev/null +++ b/run-python-scripts/hello.py @@ -0,0 +1,3 @@ +# hello.py + +print("Hello, World!") diff --git a/run-python-scripts/hello_shebang.py b/run-python-scripts/hello_shebang.py new file mode 100755 index 0000000000..01b85e848c --- /dev/null +++ b/run-python-scripts/hello_shebang.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 + +print("Hello, World!") diff --git a/run-python-scripts/run_exec.py b/run-python-scripts/run_exec.py new file mode 100644 index 0000000000..345386e1a2 --- /dev/null +++ b/run-python-scripts/run_exec.py @@ -0,0 +1,2 @@ +with open("hello.py") as hello: + exec(hello.read()) diff --git a/run-python-scripts/run_importlib.py b/run-python-scripts/run_importlib.py new file mode 100644 index 0000000000..f34d9a498f --- /dev/null +++ b/run-python-scripts/run_importlib.py @@ -0,0 +1,3 @@ +import importlib + +importlib.import_module("hello") diff --git a/run-python-scripts/run_reload.py b/run-python-scripts/run_reload.py new file mode 100644 index 0000000000..b184cfdd68 --- /dev/null +++ b/run-python-scripts/run_reload.py @@ -0,0 +1,5 @@ +import importlib + +import hello_shebang # First import. Second import does nothing + +importlib.reload(hello_shebang)