[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

if STREAM.isatty():

On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote:

> I don't understand what's to not to understand.
>    if condition:
>      do_something_because_condition_is_true()
>    else:
>      do_something_because_condition_is_false()
> is a perfectly normal construction.  If you mean something else, please
> be explicit.

Let me say it more explicitly:

The original code snippet's logic is as follows:

        if STREAM.isatty():
            p = (self.progress_template + '\r') % params
           [do something to reset the new value of p] 
           p = (self.progress_template + '\n') % params

In order to refresh the tty, the if and else must be run alternatively.  
i.e., the isatty() must return 0 and 1 periodically.  

I still understand how the above code will let the isatty() return 0 and 
1 in turn?