9 Command Line Flags To Run Python Scripts More Flexibly
Commonly used Python command-line options.
When invoking a Python script, you can specify various options/flags. They are used to modify the behavior of the Python interpreter when it runs a script or module.
Here are 9 of the most commonly used options:
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐜: Run a single Python command. Useful for running simple one-liners or testing code snippets.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐢: Run the script as usual and enter the interactive mode instead of terminating the program. Useful for debugging as you can interact with objects created during the program.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐎: Ignore assert statements (This is alphabet ‘O’). Useful for optimizing code by removing debugging code.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐎𝐎: Ignore assert statements and discard docstrings. Useful for further optimizing code by removing documentation strings.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐖: Ignore all warnings. Useful for turning off warnings temporarily and focusing on development.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐦: Run a module as a script.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐯: Enter verbose mode. Useful for printing extra information during program execution.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐱: Skip the first line. Useful for removing shebang lines or other comments at the start of a script.
🔷 𝐩𝐲𝐭𝐡𝐨𝐧 -𝐄: ignore all Python environment variables. Useful for ensuring a consistent program behavior by ignoring environment variables that may affect program execution.
Which ones have I missed? Let me know :)
👉 Read what others are saying about this post on LinkedIn.
👉 If you liked this post, don’t forget to leave a like ❤️. It helps more people discover this newsletter on Substack and tells me that you appreciate reading these daily insights. The button is located towards the bottom of this email.
👉 If you love reading this newsletter, feel free to share it with friends!
Find the code for my tips here: GitHub.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn and Twitter.