Executing Multi-Line Python Statements in a Single Command-Line Command
The Python -c option allows for one-liner loop execution, but importing modules within the command can lead to syntax errors. To address this, consider the following solutions:
echo -e "import sys\nfor r in range(10): print 'rob'" | python
python -c "exec(\"import sys\nfor r in range(10): print 'rob'\")"
(echo "import sys" ; echo "for r in range(10): print 'rob'" ) | python
As suggested by SilentGhost and Crast (not shown in this response).
These solutions allow for the execution of multi-line Python statements within a single command-line command, while also importing necessary modules.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3