Danek Duvall wrote: > On Thu, Dec 18, 2008 at 11:17:31AM -0600, Shawn Walker wrote: > >> Whenever the program exits, it was printing a set of 80 space characters >> to overwrite whatever characters had last been displayed but with a >> trailing ',' to omit the newline. >> >> However, a newline was added anyway on program exit. > > Where was that newline being added?
By python, during exit. >> By printing a carriage return after all the whitespace had overwritten >> the existing output, I was able to prevent the newline from being added >> while still achieving the desired effect. > > How does that work? [1] ==== The reason for the newline is that, when standard output (sys.output) is closed, it checks if its softspace attribute is True (meaning there is a pending line not yet terminated) and if so terminates the line. In turn, softspace is set by print with a trailing comma, specifically to avoid erroneously-unterminated lines (and other small anomalies). So, if you want something a bit out of the ordinary such as an unterminated line being output, either you eschew print, which is meant to help in typical ordinary cases (sys.stdout.write being there for when you need fine control), or you reset that special attribute to False. ==== I was wanting to avoid mucking with sys.stdout since further output could happen after the progress tracker was done. I could change to using sys.stdout.write here instead if you think that would be better? Cheers, -- Shawn Walker [1] http://bytes.com/groups/python/36896-how-does-one-keep-python-printing-newline-program-exit _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
