Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Read Medline records one by one from the handle.

The handle is either is a Medline file, a file-like object, or a list
of lines describing one or more Medline records.

Typical usage:

    from Bio import Medline
    with open("mymedlinefile") as handle:
        records = Medline.parse(handle)(more...)

        def parse(handle):
    """Read Medline records one by one from the handle.

    The handle is either is a Medline file, a file-like object, or a list
    of lines describing one or more Medline records.

    Typical usage:

        from Bio import Medline
        with open("mymedlinefile") as handle:
            records = Medline.parse(handle)
            for record in record:
                print(record['TI'])

    """
    #TODO - Turn that into a working doctest
    # These keys point to string values
    textkeys = ("ID", "PMID", "SO", "RF", "NI", "JC", "TA", "IS", "CY", "TT",
                "CA", "IP", "VI", "DP", "YR", "PG", "LID", "DA", "LR", "OWN",
                "STAT", "DCOM", "PUBM", "DEP", "PL", "JID", "SB", "PMC",
                "EDAT", "MHDA", "PST", "AB", "AD", "EA", "TI", "JT")
    handle = iter(handle)
    # First skip blank lines
    for line in handle:
        line = line.rstrip()
        if line:
            break
    else:
        return
    record = Record()
    finished = False
    while not finished:
        if line[:6] == "      ":  # continuation line
            record[key].append(line[6:])
        elif line:
            key = line[:4].rstrip()
            if not key in record:
                record[key] = []
            record[key].append(line[6:])
        try:
            line = next(handle)
        except StopIteration:
            finished = True
        else:
            line = line.rstrip()
            if line:
                continue
        # Join each list of strings into one string.
        for key in textkeys:
            if key in record:
                record[key] = " ".join(record[key])
        if record:
            yield record
        record = Record()
        


src/b/i/Bio_Eutils-1.63/Tests/test_Medline.py   Bio_Eutils(Download)
    def test_parse(self):
        handle = open("Medline/pubmed_result2.txt")
        records = Medline.parse(handle)
        record = next(records)
        self.assertEqual(record["PMID"], "16403221")