Is there a Python argument to execute code from the shell without starting up an interactive interpreter or reading from a file? Something similar to:
perl -e 'print "Hi"'
This works:
python -c 'print("Hi")'
Hi
From the manual, man python:
-c command Specify the command to execute (see next section). This termi- nates the option list (following options are passed as arguments to the command).
; to separate statements, e.g., python -c 'import foo; foo.bar()'Traceback (most recent call last): File "<string>", line 1, in <module> NameError: name 'Hi' is not defined-i: python -i -c 'a = 5' >>> a 5A 'heredoc' can be used to directly feed a script into the python interpreter:
python <<HEREDOC
import sys
for p in sys.path:
print(p)
HEREDOC
/usr/lib64/python36.zip
/usr/lib64/python3.6
/usr/lib64/python3.6/lib-dynload
/home/username/.local/lib/python3.6/site-packages
/usr/local/lib/python3.6/site-packages
/usr/lib64/python3.6/site-packages
/usr/lib/python3.6/site-packages
bash)? I am trying to add "> temp.txt" after the command and also to use a pipe and other ideas, but the file is zero length.> temp.txt" after the first HEREDOC on the first line in your example., i.e., do: "$ python <<HEREDOC > temp.txt"pip install e. For a standard python install, this produces the error: No module named e.
-cis the second option described in themanpage.