def print_err(*args, **kwargs):
    """ A wrapper for print() that uses stderr by default. """
    if kwargs.get('file', None) is None:
        kwargs['file'] = sys.stderr

    color = dict_pop_or(kwargs, 'color', True)
    # Use color if asked, but only if the file is a tty.
    if color and kwargs['file'].isatty():
        # Keep any Colr args passed, convert strs into Colrs.
        msg = kwargs.get('sep', ' ').join(
            str(a) if isinstance(a, C) else str(C(a, 'red'))
            for a in args
        )
    else:
        # The file is not a tty anyway, no escape codes.
        msg = kwargs.get('sep', ' ').join(
            str(a.stripped() if isinstance(a, C) else a)
            for a in args
        )
    newline = dict_pop_or(kwargs, 'newline', False)
    if newline:
        msg = '\n{}'.format(msg)
    print(msg, **kwargs)
def print_err ( * args , ** kwargs ) : if kwargs . get ( 'file' , None ) is None : kwargs [ 'file' ] = sys . stderr color = dict_pop_or ( kwargs , 'color' , True ) if color and kwargs [ 'file' ] . isatty ( ) : msg = kwargs . get ( 'sep' , ' ' ) . join ( str ( a ) if isinstance ( a , C ) else str ( C ( a , 'red' ) ) for a in args ) else : msg = kwargs . get ( 'sep' , ' ' ) . join ( str ( a . stripped ( ) if isinstance ( a , C ) else a ) for a in args ) newline = dict_pop_or ( kwargs , 'newline' , False ) if newline : msg = '\n{}' . format ( msg ) print ( msg , ** kwargs )
A wrapper for print() that uses stderr by default.