On Wed, Dec 23, 2020 at 9:15 AM Steven D'Aprano steve@pearwood.info wrote:
On Mon, Dec 21, 2020 at 08:22:35AM +1100, Cameron Simpson wrote:
is it so bad to use a subprocess?
Yes. It is _really slow_, depends on external reaources which might not be there, and subprocess brings other burdens too. Python comes with curses and that knows directly how to do this.
Do you have benchmarks showing that shelling out to "clear" or "cls" is actually slower than running the full curses machinery for this?
IPython claims that the magic `%clear` command shells out to `clear`, are there complaints about the time it takes to clear the screen?
On my computer, shelling out to "clear" takes about one hundredth of a millisecond, which in interactive use is pretty much instantaneous. Do you have examples of tight loops where this would be a bottleneck?
A tight loop clearing the screen? If you have that, you have much bigger problems :) And yes, I've seen that happen, usually because something doesn't know about cursor movement calls. (It looks UGLY.)
But shelling out to clear/cls has another problem: it's a big ol' dependency. You need to have the corresponding command, and it needs to be accessible on $PATH, and so on and so forth. I'd rather a more complicated system of ANSI escape sequence management than something that depends on an external command; it's only going to be a half page of code to do it inside Python.
ChrisA