On Wed, Dec 23, 2020 at 9:15 AM Steven D'Aprano <st...@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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RTRJO5P3A35YQXBRIZLBGFBNJIVJJABQ/ Code of Conduct: http://python.org/psf/codeofconduct/