Sometimes, we want to run multi-line statements in the one-line command-line with Python.
In this article, we’ll look at how to run multi-line statements in the one-line command-line with Python.
How to run multi-line statements in the one-line command-line with Python?
To run multi-line statements in the one-line command-line with Python, we can use pipe.
For instance, we write
echo -e "import sysnfor r in range(10): print('rob')" | python
to add code into the double quotes with the n
character to add new lines between lines.
And then we echo the string with echo -e
to backslash escape the string and pipe the result to python
to run it.
Conclusion
To run multi-line statements in the one-line command-line with Python, we can use pipe.