<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(p_file, p_string):
 """ Write p_string to file p_file, trailed by a newline character. ANSI codes are removed when the file is not a TTY (and colors are automatically determined). """

    if not config().colors(p_file.isatty()):
        p_string = escape_ansi(p_string)

    if p_string:
        p_file.write(p_string + "\n")