How to programmatically retrieve the interpreter options passed to the python interpreter within that instance?
For example, given command
python -B -u script.py
what Python code lists the passed interpreter command-line options -B
and -u
?
I could query sys.dont_write_bytecode
to infer that command-line option -B
was passed. But I want Python code that is generic to any interpreter option. I imagine a code snippet that would return a list of command-line options the interpreter was given, e.g. [ '-B', '-u' ]
.
To question reviewers, this question is not answered in How to get python interpreter full argv command line options?. That answer for that question suggests changing the C-runtime code of the interpreter and recompiling Python. That is not a suitable solution for my needs.