I noticed in the python doc that there is a -c
flag. Here is what python doc says:
Execute the Python code in command. command can be one or more statements separated by newlines, with significant leading whitespace as in normal module code.
There is no example in the doc and I couldn't figure out how to make this work, and also in what situations it may help.
Anyone have any clue?
Python Language Regular Expressions (Regex) FlagsFor some special cases we need to change the behavior of the Regular Expression, this is done using flags. Flags can be set in two ways, through the flags keyword or directly in the expression.
In the Python source code, you can find this more extensive list of flags in code.h: Show activity on this post. These FLAGS signify different components of a code object. While the other answer points you towards the right answer, I am just adding a little fun to the mix. You can try importing a subset of FLAGS from dis.
Python regex allows optional flags to specify when using regular expression patterns with match (), search (), and split (), among others. All RE module methods accept an optional flags argument that enables various unique features and syntax variations. For example, you want to search a word inside a string using regex.
You can enhance this regex’s capability by adding the RE.I flag as an argument to the search method to enable case-insensitive searching. You will learn how to use all regex flags available in Python with short and clear examples. First, refer to the below table for available regex flags.
Every command-line executable has some flags to configure it while it runs. Some of the popular flags include –help to get idea documentation about executable, -v to check the executable version, and -m flag to run a Python module. Although there are many other flags available, only a few of them are actually useful.
Just pass regular Python code as the argument to the flag:
python -c 'print 1 print 2'
Import modules works, and blank lines are OK, too:
python -c ' import pprint pprint.pprint(1) '
When using this feature, just be mindful of shell quoting (and indentation), and keep in mind that if you're using this outside of a few shell scripts, you might be doing it wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With