def writeto(fpath, to_write, aslines=False, verbose=None):
if verbose:<EOL><INDENT>print('<STR_LIT>' % (fpath,))<EOL><DEDENT>with open(fpath, '<STR_LIT:wb>') as file:<EOL><INDENT>if aslines:<EOL><INDENT>to_write = map(_ensure_bytes , to_write)<EOL>file.writelines(to_write)<EOL><DEDENT>else:<EOL><INDENT>bytes = _ensure_bytes(to_write)<EOL>file.write(bytes)<EOL><DEDENT><DEDENT>
r"""
    Writes (utf8) text to a file.

    Args:
        fpath (PathLike): file path
        to_write (str): text to write (must be unicode text)
        aslines (bool): if True to_write is assumed to be a list of lines
        verbose (bool): verbosity flag

    CommandLine:
        python -m ubelt.util_io writeto --verbose

    Example:
        >>> import ubelt as ub
        >>> dpath = ub.ensure_app_cache_dir('ubelt')
        >>> fpath = dpath + '/' + 'testwrite.txt'
        >>> if exists(fpath):
        >>>     os.remove(fpath)
        >>> to_write = 'utf-8 symbols Δ, Й, ק, م, ๗, あ, 叶, 葉, and 말.'
        >>> writeto(fpath, to_write)
        >>> read_ = ub.readfrom(fpath)
        >>> print('read_    = ' + read_)
        >>> print('to_write = ' + to_write)
        >>> assert read_ == to_write

    Example:
        >>> import ubelt as ub
        >>> dpath = ub.ensure_app_cache_dir('ubelt')
        >>> fpath = dpath + '/' + 'testwrite2.txt'
        >>> if exists(fpath):
        >>>     os.remove(fpath)
        >>> to_write = ['a\n', 'b\n', 'c\n', 'd\n']
        >>> writeto(fpath, to_write, aslines=True)
        >>> read_ = ub.readfrom(fpath, aslines=True)
        >>> print('read_    = {}'.format(read_))
        >>> print('to_write = {}'.format(to_write))
        >>> assert read_ == to_write