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.

Reply

or to participate.