def save_cookiestxt(fp, cookies):
    """Write 'cookies' in Netscape cookies.txt format to 'fp'"""
    fp.write('# Netscape HTTP Cookie File\n\n')
    for cookie in cookies:
        if cookie.value is None:
            name = ''
            value = cookie.name
        else:
            name = cookie.name
            value = cookie.value
        fp.write('\t'.join((cookie.domain, 'TRUE' if cookie.domain.
            startswith('.') else 'FALSE', cookie.path, 'TRUE' if cookie.
            secure else 'FALSE', '0' if cookie.expires is None else str(
            cookie.expires), name, value)) + '\n')
