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

All Samples(4)  |  Call(4)  |  Derive(0)  |  Import(0)
Parses an XML file from the NCBI Entrez Utilities into python objects.

This function parses an XML file created by NCBI's Entrez Utilities,
returning a multilevel data structure of Python lists and dictionaries.
This function is suitable for XML files that (in Python) can be represented
as a list of individual records. Whereas 'read' reads the complete file
and returns a single Python list, 'parse' is a generator function that
returns the records one by one. This function is therefore particularly
useful for parsing large files.
(more...)

        def parse(handle, validate=True):
    """Parses an XML file from the NCBI Entrez Utilities into python objects.

    This function parses an XML file created by NCBI's Entrez Utilities,
    returning a multilevel data structure of Python lists and dictionaries.
    This function is suitable for XML files that (in Python) can be represented
    as a list of individual records. Whereas 'read' reads the complete file
    and returns a single Python list, 'parse' is a generator function that
    returns the records one by one. This function is therefore particularly
    useful for parsing large files.

    Most XML files returned by NCBI's Entrez Utilities can be parsed by
    this function, provided its DTD is available. Biopython includes the
    DTDs for most commonly used Entrez Utilities.

    If validate is True (default), the parser will validate the XML file
    against the DTD, and raise an error if the XML file contains tags that
    are not represented in the DTD. If validate is False, the parser will
    simply skip such tags.

    Whereas the data structure seems to consist of generic Python lists,
    dictionaries, strings, and so on, each of these is actually a class
    derived from the base type. This allows us to store the attributes
    (if any) of each element in a dictionary my_element.attributes, and
    the tag name in my_element.tag.
    """
    from .Parser import DataHandler
    handler = DataHandler(validate)
    records = handler.parse(handle)
    return records
        


src/b/i/Bio_Eutils-1.63/Tests/test_Entrez.py   Bio_Eutils(Download)
        handle.close()
        handle = open('GenBank/NT_019265.gb', "rb")
        iterator = Entrez.parse(handle)
        self.assertRaises(Parser.NotXMLError, next, iterator)
        handle.close()
        handle.close()
        handle = open('Fasta/wisteria.nu', "rb")
        iterator = Entrez.parse(handle)
        self.assertRaises(Parser.NotXMLError, next, iterator)
        handle.close()
        # Test if the error is also raised with Entrez.parse
        handle = open('Entrez/pubmed3.html', "rb")
        records = Entrez.parse(handle)
        self.assertRaises(Parser.NotXMLError, next, records)
        handle.close()
        # Test if the error is also raised with Entrez.parse
        handle = open('Entrez/journals.xml', "rb")
        records = Entrez.parse(handle)
        self.assertRaises(Parser.NotXMLError, next, records)
        handle.close()