heredoc

python -c vs python -<< heredoc

python -c vs python -<< heredoc Question: I am trying to run some piece of Python code in a Bash script, so i wanted to understand what is the difference between: #!/bin/bash #your bash code python -c ” #your py code ” vs python – <<DOC #your py code DOC I checked the web but …

Total answers: 4

Python here document without newlines at top and bottom

Python here document without newlines at top and bottom Question: What’s the best way to have a here document, without newlines at the top and bottom? For example: print ”’ dog cat ”’ will have newlines at the top and bottom, and to get rid of them I have to do this: print ”’dog cat”’ …

Total answers: 6

Executing multi-line statements in the one-line command-line

Executing multi-line statements in the one-line command-line Question: I’m using Python with -c to execute a one-liner loop, i.e.: python -c "for r in range(10): print ‘rob’" This works fine. However, if I import a module before the for loop, I get a syntax error: python -c "import sys; for r in range(10): print ‘rob’" …

Total answers: 18