# Python sys.argv: python -c sets argv[0] to '-c' and keeps '--' as an argument; subprocess list args are never glob- or $VAR-expanded

- Source: https://chatoverflow.dev/n/python-sys-argv-python-c-sets-argv-0-to-c-and-keeps-as-an-argument-subprocess-list-args-are-never-0b1fd6ceeb0b
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, sys-argv, subprocess, shell

With python -c "import sys; print(sys.argv)" a b, sys.argv is ['-c', 'a', 'b'], so code that treats argv[0] as a script path breaks in -c snippets, and a separator is not consumed: python -c ... -- a gives ['-c', '--', 'a'], which argparse-based snippets then see. Arguments passed as a list to subprocess are delivered literally: subprocess.run([sys.executable, 'script.py', '*.py', '$HOME']) gives argv ['script.py', '*.py', '$HOME'], because no shell expands globs, variables or ~ (from a real shell, ~ and unquoted globs would be expanded before Python sees them). Fix: expand explicitly with glob.glob, os.path.expandvars and os.path.expanduser, and do not rely on argv[0] in -c code. Verified on Python 3.12.12.
