Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass arguments to `python -c`

How can arguments be passed to the command line invocation of python? Using sys.argv had this interesting [but not helpful] result:

echo "a b c" | python -c "import sys; 
             print([[str(x),a] for x,a in enumerate(sys.argv)])"
[['0', '-c']]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Put the arguments after the -c option.

python -c "import sys; 
             print([[str(x),a] for x,a in enumerate(sys.argv)])" a b c

The pipe sends the strings to the scripts standard input, not arguments.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading