Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I saw in the python doc that there is a - c flag. Here is the thing that python doc says: 

Execute the Python code in command. command can be one or more statements separated by newlines, with significant leading whitespace as in normal module code.

There is no model in the doc and I was unable to sort out some way to make this work, and furthermore in what circumstances it might help. 

Does anybody have any hint?

1 Answer

0 votes
by (26.4k points)

Simply pass regular Python code as the argument to the flag: 

python -c 'print 1

print 2'

Import modules works, and clear lines are OK, as well: 

python -c '

import pprint

pprint.pprint(1)

'

When utilizing this component, simply be aware of shell quoting (and space), and remember that in case you're utilizing this outside of a couple of shell contents, you may be treating it terribly.

Join the python online course fast, to learn python concepts in detail and get certified.

Related questions

Browse Categories

...