"""
Remove comments from bib file.
"""
from textx import metamodel_for_language
from txbibtex import bibentry_str

BIB_FILE = 'references.bib'
bibfile = metamodel_for_language('bibtex').model_from_file(BIB_FILE)

# Drop line comments.
print('\n'.join([bibentry_str(e) for e in bibfile.entries
                 if e.__class__.__name__ != 'BibLineComment']))

[((8, 10, 8, 42), 'textx.metamodel_for_language', 'metamodel_for_language', ({(8, 33, 8, 41): '"""bibtex"""'}, {}), "('bibtex')", False, 'from textx import metamodel_for_language\n'), ((11, 17, 11, 32), 'txbibtex.bibentry_str', 'bibentry_str', ({(11, 30, 11, 31): 'e'}, {}), '(e)', False, 'from txbibtex import bibentry_str\n')]