code: def write_events(filename, events, *, overwrite=False, verbose=None):
      """Write :term:`events` to file.
  
      Parameters
      ----------
      filename : path-like
          Name of the output file.
          If the extension is ``.fif``, events are written in
          binary FIF format, otherwise (e.g., ``.eve``,
          ``.lst``, ``.txt``) events are written as plain text.
          Note that new format event files do not contain
          the ``"time"`` column (used to be the second column).
      %(events)s
      %(overwrite)s
      %(verbose)s
  
      See Also
      --------
      read_events
      """
      filename = _check_fname(filename, overwrite=overwrite)
      check_fname(
          filename,
          "events",
          (
              ".eve",
              "-eve.fif",
              "-eve.fif.gz",
              "-eve.lst",
              "-eve.txt",
              "_eve.fif",
              "_eve.fif.gz",
              "_eve.lst",
              "_eve.txt",
          ),
      )
      if filename.suffix in (".fif", ".gz"):
          #   Start writing...
          with start_and_end_file(filename) as fid:
              start_block(fid, FIFF.FIFFB_MNE_EVENTS)
              write_int(fid, FIFF.FIFF_MNE_EVENT_LIST, events.T)
              end_block(fid, FIFF.FIFFB_MNE_EVENTS)
      else:
          with open(filename, "w") as f:
              for e in events:
                  f.write("%6d %6d %3d\n" % tuple(e))
  
imports: from collections.abc import Sequence
  from pathlib import Path
  import numpy
  from ._fiff.constants import FIFF
  from ._fiff.open import fiff_open
  from ._fiff.pick import pick_channels
  from ._fiff.tag import read_tag
  from ._fiff.tree import dir_tree_find
  from ._fiff.write import end_block, start_and_end_file, start_block, write_int
  from .utils import _check_fname, _check_integer_or_list, _check_on_missing, _check_option, _get_stim_channel, _on_missing, _pl, _validate_type, check_fname, fill_doc, logger, verbose, warn
label_desc: Use image node_id 5 for calling a global function with example usage: write_events(filename, events) without return types