I'm using IDLE (Python 2.7) on Debian Wheezy. I sourced questions here and here. I tried applying what they said, and I got some strange results. If I print carriage returns or backspaces in the Python shell, rather than actually getting those, I get squares with bs
and cr
in them. I can't show them here because they don't copy over.
How can I get an actual carriage return? This is my code, based on the questions I cited above:
sys.stdout.write("Extracted: %d% Skipped %d% \r" % (len(f),len(skipped)))
sys.stdout.flush()
Terminals vary in their capabilites of handling such special characters. A similar question was answered by Wayne Werner, who said that IDLE just does not handle those special characters (i.e. printing a stand-in character, rather than moving the cursor or deleting.), which may be for good reason.
Short of writing a patch as Wayne mentioned, you may find that running your program in the native terminal does work as expected. (i.e. python path/to/your/program
).
If you would like the program to be aware of it's environment (as was asked in the comments) it is possible (and perhaps most simple) to create a command line switch that is set manually at the program's execution. If you launch from a shortcut or another program (perhaps a batch file) you could automate the process by incorporating it into the pre-written command.
Such a switch could look like:
python path/to/your/program --terminal //For a full terminal
python path/to/your/program --IDLE //For IDLE
After reading Terry Jan Reedy's comment, I'd to point out that his guidance toward tkinter(and on the general facets of this situation) may in fact be the most helpful for a thorough solution to the issue. Check those comments out.