How to use the -c flag in python

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)