For copy and paste purposes, I wish to hide the >>> and ... Python prompts whenever I am in the interactive shell console. I have achieved this effect successfully with the command import sys, then sys.ps1 = "" (source). However that only hides >>>. Furthermore, a flag would simplify the work, and since other languages have this type of flag, I wonder if I'm not reinventing the wheel.
In database programming with Db2, for example, there is a +p flag. As it is described negatively, it does the opposite of -p:
The -p option tells the command line processor to display the command line processor prompt when the user is in interactive mode.
Any shortcuts?
python -i scriptname.pyrunsscriptname.py, then drops you to an interactive shell. If that script clearssys.ps1andsys.ps2, then the interactive shell will be one that doesn't print prompts.Even better, you can use the shell feature process substitution to create a temporary filename (something like
/dev/fd/10, depending on your OS) that, when read, contains exactly the script you want:...if placed in your
.bashrc, will define a commandpnp("python, no prompt") that does the above.