If I run a python script via python foo.py then I can get the contents of the script by reading the file sys.argv[0]. Is it possible to get the contents of the script (e.g., as a string) if the script is passed to the python interpreter via python -c "$(cat foo.py)"?
No. As far as I know, It wont be possible. When you call "$(cat foo.py)", shell will get only the contents and the reference is lost.
Get the text of a python script that is passed via the `-c` option