code: def _wrpy_ncbi_gene_nts(fout_py, geneid2nt, log):
          
          num_genes = len(geneid2nt)
          with open(fout_py, 'w') as ofstrm:
              docstr = "Data downloaded from NCBI Gene converted into Python namedtuples."
              ofstrm.write('"""{PYDOC}"""\n\n'.format(PYDOC=docstr))
              ofstrm.write("from collections import namedtuple\n\n")
              ofstrm.write('WRITTEN = "{DATE}"'.format(
                  DATE=re.sub('-', '_', str(datetime.date.today()))))
              ofstrm.write(' # {N} items\n\n'.format(N=num_genes))
              ntd = next(iter(geneid2nt.values())) # Access one dictionary value in Python 2
              ofstrm.write("#pylint: disable=line-too-long,too-many-lines,invalid-name\n")
              ofstrm.write("{NtName} = namedtuple('{NtName}', '{FLDS}')\n\n".format(
                  NtName=type(ntd).__name__, FLDS=' '.join(ntd._fields)))
              ofstrm.write("GENEID2NT = {{ # {N:,} items\n".format(N=num_genes))
              for geneid, ntd in sorted(geneid2nt.items(), key=lambda t: t[0]):
                  ofstrm.write("    {GeneID} : {NT},\n".format(GeneID=geneid, NT=ntd))
              ofstrm.write("}\n")
              log.write("  {N:9} geneids WROTE: {PY}\n".format(N=num_genes, PY=fout_py))
docs: Write namedtuples to a dict in a Python module.