Created
January 13, 2026 12:39
-
-
Save lassebenni/98ed9f6f746a53a320eb3426b5ce2883 to your computer and use it in GitHub Desktop.
Terminal Tutorial: __name__ == __main__ pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"version":2,"width":80,"height":24,"timestamp":1768307943,"command":"python3 actor_name_main.py","env":{"SHELL":"/bin/zsh"}} | |
| [0.093267, "o", "\r\n\u001b[1;36m=== Demonstrating: if __name__ == \"__main__\" ===\u001b[0m\r\n\r\n"] | |
| [1.093391, "o", "\u001b[1;33m# Let's look at our module with the __main__ pattern:\u001b[0m\r\n\r\n"] | |
| [1.59714, "o", "$ c"] | |
| [1.636309, "o", "a"] | |
| [1.715234, "o", "t"] | |
| [1.791043, "o", " "] | |
| [1.826789, "o", "d"] | |
| [1.893022, "o", "e"] | |
| [1.938075, "o", "m"] | |
| [2.014439, "o", "o"] | |
| [2.082558, "o", "_"] | |
| [2.145612, "o", "m"] | |
| [2.221357, "o", "o"] | |
| [2.300573, "o", "d"] | |
| [2.36547, "o", "u"] | |
| [2.411675, "o", "l"] | |
| [2.45304, "o", "e"] | |
| [2.529805, "o", "."] | |
| [2.602101, "o", "p"] | |
| [2.636334, "o", "y"] | |
| [2.704718, "o", "\r\n"] | |
| [3.007279, "o", "\u001b[38;5;141mdef\u001b[0m \u001b[38;5;81mclean_string\u001b[0m(value):\r\n \u001b[38;5;243m\"\"\"Remove whitespace and lowercase.\"\"\"\u001b[0m\r\n \u001b[38;5;141mreturn\u001b[0m str(value).strip().lower()\r\n\r\n\u001b[38;5;141mif\u001b[0m __name__ == \u001b[38;5;113m\"__main__\"\u001b[0m:\r\n \u001b[38;5;243m# This only runs when executed directly\u001b[0m\r\n print(\u001b[38;5;113m\"Testing clean_string...\"\u001b[0m)\r\n print(clean_string(\u001b[38;5;113m\" HELLO \"\u001b[0m))\r\n\r\n"] | |
| [4.509077, "o", "\u001b[1;33m# Running the file directly → test code RUNS:\u001b[0m\r\n\r\n"] | |
| [5.011524, "o", "$ p"] | |
| [5.090597, "o", "y"] | |
| [5.154714, "o", "t"] | |
| [5.236313, "o", "h"] | |
| [5.278206, "o", "o"] | |
| [5.320736, "o", "n"] | |
| [5.386332, "o", " "] | |
| [5.421248, "o", "d"] | |
| [5.461844, "o", "e"] | |
| [5.54296, "o", "m"] | |
| [5.620904, "o", "o"] | |
| [5.696065, "o", "_"] | |
| [5.743975, "o", "m"] | |
| [5.779053, "o", "o"] | |
| [5.821125, "o", "d"] | |
| [5.861795, "o", "u"] | |
| [5.92698, "o", "l"] | |
| [5.982063, "o", "e"] | |
| [6.047183, "o", "."] | |
| [6.111708, "o", "p"] | |
| [6.16123, "o", "y"] | |
| [6.19603, "o", "\r\n"] | |
| [6.50156, "o", "Testing clean_string...\r\nhello\r\n\r\n"] | |
| [8.003098, "o", "\u001b[1;33m# Importing the module → test code does NOT run:\u001b[0m\r\n\r\n"] | |
| [8.504729, "o", "$ p"] | |
| [8.53746, "o", "y"] | |
| [8.596939, "o", "t"] | |
| [8.63634, "o", "h"] | |
| [8.679545, "o", "o"] | |
| [8.746138, "o", "n"] | |
| [8.810173, "o", " "] | |
| [8.858212, "o", "-"] | |
| [8.936391, "o", "c"] | |
| [8.978073, "o", " "] | |
| [9.053391, "o", "\""] | |
| [9.120961, "o", "i"] | |
| [9.16148, "o", "m"] | |
| [9.235601, "o", "p"] | |
| [9.302976, "o", "o"] | |
| [9.340395, "o", "r"] | |
| [9.4019, "o", "t"] | |
| [9.455909, "o", " "] | |
| [9.512744, "o", "d"] | |
| [9.552236, "o", "e"] | |
| [9.604391, "o", "m"] | |
| [9.654669, "o", "o"] | |
| [9.712143, "o", "_"] | |
| [9.764256, "o", "m"] | |
| [9.847079, "o", "o"] | |
| [9.928208, "o", "d"] | |
| [9.976778, "o", "u"] | |
| [10.041331, "o", "l"] | |
| [10.07981, "o", "e"] | |
| [10.164569, "o", ";"] | |
| [10.228907, "o", " "] | |
| [10.269911, "o", "p"] | |
| [10.32932, "o", "r"] | |
| [10.412257, "o", "i"] | |
| [10.468896, "o", "n"] | |
| [10.544986, "o", "t"] | |
| [10.595197, "o", "("] | |
| [10.676778, "o", "d"] | |
| [10.750374, "o", "e"] | |
| [10.790919, "o", "m"] | |
| [10.831339, "o", "o"] | |
| [10.871263, "o", "_"] | |
| [10.953035, "o", "m"] | |
| [11.011859, "o", "o"] | |
| [11.059212, "o", "d"] | |
| [11.115831, "o", "u"] | |
| [11.15218, "o", "l"] | |
| [11.203136, "o", "e"] | |
| [11.247099, "o", "."] | |
| [11.303209, "o", "c"] | |
| [11.361508, "o", "l"] | |
| [11.437894, "o", "e"] | |
| [11.50378, "o", "a"] | |
| [11.572138, "o", "n"] | |
| [11.622293, "o", "_"] | |
| [11.70405, "o", "s"] | |
| [11.75423, "o", "t"] | |
| [11.830787, "o", "r"] | |
| [11.890937, "o", "i"] | |
| [11.931361, "o", "n"] | |
| [11.991417, "o", "g"] | |
| [12.036599, "o", "("] | |
| [12.094996, "o", "'"] | |
| [12.174363, "o", " "] | |
| [12.247103, "o", " "] | |
| [12.297488, "o", "W"] | |
| [12.347134, "o", "O"] | |
| [12.396002, "o", "R"] | |
| [12.428511, "o", "L"] | |
| [12.488274, "o", "D"] | |
| [12.536345, "o", " "] | |
| [12.587934, "o", " "] | |
| [12.637254, "o", "'"] | |
| [12.672419, "o", ")"] | |
| [12.749216, "o", ")"] | |
| [12.787107, "o", "\""] | |
| [12.840347, "o", "\r\n"] | |
| [13.143566, "o", "world\r\n\r\n"] | |
| [14.144155, "o", "\u001b[1;32m✓ The __main__ pattern lets your file work as both\u001b[0m\r\n\u001b[1;32m a reusable module AND a standalone script!\u001b[0m\r\n\r\n"] | |
| [16.152598, "x", "0"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Terminal Tutorial: __name__ == "__main__"</title> | |
| <link rel="stylesheet" type="text/css" href="https://unpkg.com/asciinema-player@3.6.3/dist/bundle/asciinema-player.css" /> | |
| <style> | |
| body { margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background: #121212; color: #eee; font-family: sans-serif; } | |
| #player { width: 100%; max-width: 900px; box-shadow: 0 4px 6px rgba(0,0,0,0.3); } | |
| .error { color: #ff5555; text-align: center; padding: 20px; border: 1px solid #ff5555; border-radius: 4px; background: rgba(255,0,0,0.1); } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="player"></div> | |
| <script src="https://unpkg.com/asciinema-player@3.6.3/dist/bundle/asciinema-player.min.js"></script> | |
| <script> | |
| window.addEventListener('load', function() { | |
| setTimeout(function() { | |
| if (typeof AsciinemaPlayer === 'undefined') { | |
| document.getElementById('player').innerHTML = '<div class="error"><strong>Error:</strong> AsciinemaPlayer failed to load.</div>'; | |
| return; | |
| } | |
| AsciinemaPlayer.create('name_main_demo.cast', document.getElementById('player'), { | |
| autoPlay: true, preload: true, rows: 20, cols: 70, theme: 'monokai', idleTimeLimit: 2 | |
| }); | |
| }, 100); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment