Home >Backend Development >Python Tutorial >How to Execute Multi-Line Python Commands in a Single Makefile Command?
Multi-Line Command Execution in a One-Line Makefile Command
When executing Python commands from the command line with the -c option, a syntax error occurs when importing a module before a multi-line loop. To resolve this issue, there are several approaches to consider:
Echoing to the Python Interpreter:
echo -e "import sys\nfor r in range(10): print 'rob'" | python
Using Python's exec Function:
python -c "exec(\"\"\"import sys\nfor r in range(10): print 'rob'\"\"\")"
Chaining Echo Commands:
(echo "import sys" ; echo "for r in range(10): print 'rob'" ) | python
These solutions allow the execution of multi-line commands within a single line, enabling the integration of Python code into Makefiles.
The above is the detailed content of How to Execute Multi-Line Python Commands in a Single Makefile Command?. For more information, please follow other related articles on the PHP Chinese website!