python - Object is not defined -


i have problem code. program designed parse file, select information , save them in list of objects of class.

but first - not save them correctly. in fact, nothing save, returns empty records.

i tried create minimum of code entirely , work on it. next not work. can not display objects not know if correctly saves them in class. changed xml smaller , sample see if search mistake.

i think on long time, i'm running out of ideas, ask clue.

minimum code

from xml.dom import minidom  class prot():     def __init__(self, name=''):         self.name = name      def addname(self, name):         k in range(len(entry_list)):             names = entry_list[k].getelementsbytagname("names")             u in range(len(names)):                 nam = names[u].getelementsbytagname("name")                 name.append(nam[u].firstchild.nodevalue)                 print(nam[u].firstchild.nodevalue)  xml = minidom.parse('residues.xml')  entry_list = xml.getelementsbytagname("entry") mod_list = [] e in range(len(entry_list)):     m = prot(e)     mod_list.append(m) 

xml - 1 record

<entry id="aa0003"> <header> <code>aa0003</code> <dates> <creationdate>31-mar-1995</creationdate> <strucrevdate>31-mar-1995</strucrevdate> <textchngdate>30-sep-2010</textchngdate> </dates> </header> <names> <name>l-asparagine</name> <alternatename>2,4-bis(azanyl)-4-oxobutanoic acid</alternatename> <alternatename>2,4-diamino-4-oxobutanoic acid</alternatename> <alternatename>2-amino-3-carbamoylpropanoic acid</alternatename> <alternatename>2-amino-4-butanediamic acid</alternatename> <alternatename>2-aminosuccinamic acid</alternatename> <alternatename>2-aminosuccinic acid 4-amide</alternatename> <alternatename>alpha-amino-beta-carbamylpropionic acid</alternatename> <alternatename>alpha-aminosuccinamic acid</alternatename> <alternatename>aspartic acid 4-amide</alternatename> <alternatename>aspartic acid beta-amide</alternatename> <alternatename>beta-asparagine</alternatename> <systematicname>(2s)-2-amino-4-butanediamic acid</systematicname> <xref>cas:70-47-3</xref> <xref>chebi:50347</xref> <xref>pdbhet:asn</xref> </names> <formulablock> <formula>c 4 h 6 n 2 o 2</formula> <weight type="chemical">114.10</weight> <weight type="physical">114.042927</weight> </formulablock> <correctionblock uids="aa0003" label="asn"> <formula>c 0 h 0 n 0 o 0</formula> <weight type="chemical">0.00</weight> <weight type="physical">0.000000</weight> </correctionblock> <correctionblock uids="aa0004" label="asp"> <formula>c 0 h 1 n 1 o -1</formula> <weight type="chemical">-0.98</weight> <weight type="physical">-0.984016</weight> </correctionblock> <referenceblock> <authors> <author>vauquelin, l.n.</author> <author>robiquet, p.j.</author> </authors> <citation>ann. chim. 57, 88-93, 1806</citation> <title> découverte d'un nouveau principe végétal dans les asperges (asparagus sativus, linn.) [the discovery of new plant principle in asparagus (asparagus sativus, l.)]. </title> <note>article in french; isolation , naming</note> </referenceblock> <referenceblock> <authors> <author>drenth, j.</author> <author>jansonius, j.n.</author> <author>koekoek, r.</author> <author>swen, h.m.</author> <author>wolthers, b.g.</author> </authors> <citation>nature 218, 929-932, 1968</citation> <title>structure of papain.</title> <xref>doi:10.1038/218929a0</xref> <xref>pmid:5681232</xref> <note> asparagine active site residue in thiol proteinase </note> </referenceblock> <referenceblock> <authors> <anonymous/> <group> iupac-iub joint commission on biochemical nomenclature (jcbn) </group> </authors> <citation>eur. j. biochem. 138, 9-37, 1984</citation> <title> nomenclature , symbolism amino acids , peptides. recommendations 1983. </title> <xref>doi:10.1111/j.1432-1033.1984.tb07877.x</xref> <xref>pmid:6692818</xref> <note> standard three-letter , one-letter symbols, , nomenclature </note> </referenceblock> <referenceblock> <authors> <author>curnow, a.w.</author> <author>tumbula, d.l.</author> <author>pelaschier, j.t.</author> <author>min, b.</author> <author>soll, d.</author> </authors> <citation> proc. natl. acad. sci. u.s.a. 95, 12838-12843, 1998 </citation> <title> glutamyl-trna(gln) amidotransferase in deinococcus radiodurans may confined asparagine biosynthesis. </title> <xref>doi:10.1073/pnas.95.22.12838</xref> <xref>pmid:9789001</xref> <note> "mischarged" aspartyl-trna(asn) amidated glutamyl-trna(gln) amidotransferase in deinococcus radiodurans </note> </referenceblock> <referenceblock> <authors> <author>paradisi, f.</author> <author>dean, j.l.</author> <author>geoghegan, k.f.</author> <author>engel, p.c.</author> </authors> <citation>biochemistry 44, 3636-3643, 2005</citation> <title> spontaneous chemical reversion of active site mutation: deamidation of asparagine residue replacing catalytic aspartic acid of glutamate dehydrogenase. </title> <xref>doi:10.1021/bi047679u</xref> <xref>pmid:15736973</xref> <note> asp asn mutation @ enzyme active site seemingly has partial activity; however, asparagine form shown inactive, , enhanced spontaneous deamidation results in partial recovery of activity </note> </referenceblock> <referenceblock> <authors> <author>kolodkin-gal, i.</author> <author>hazan, r.</author> <author>gaathon, a.</author> <author>carmeli, s.</author> <author>engelberg-kulka, h.</author> </authors> <citation>science 318, 652-655, 2007</citation> <title> linear pentapeptide quorum-sensing factor required mazef-mediated cell death in escherichia coli. </title> <xref>doi:10.1126/science.1147248</xref> <xref>pmid:17962566</xref> <note> enzymatic amidation of aspartic acid residue in peptide; enzyme identified activity different new activity </note> </referenceblock> <comment> bacteria or archaea incorporate asparagine produced amidation of aspartyl-trna(asn). </comment> <generatingenzyme> <enzymename link="asn">aspartate--trna(asn) ligase (ec 6.1.1.23)</enzymename> <enzymename link="asn"> asparaginyl-trna synthase (glutamine-hydrolysing) (ec 6.3.5.6) </enzymename> <enzymename link="asp">aspartate--ammonia ligase (ec 6.3.1.1)</enzymename> </generatingenzyme> <sequencecode link="asn"> <sequencespec>n</sequencespec> <abbreviation>asn</abbreviation> <xref>psi-mod:00012</xref> </sequencecode> <sequencecode link="asp"> <sequencespec>d</sequencespec> <xref>psi-mod:01185</xref> </sequencecode> <source>natural</source> <features> <feature type="uniprot" key="act_site____n" link="asn">act_site</feature> <feature type="uniprot" key="mod_res__amidated aspartic acid__d" link="asp">mod_res amidated aspartic acid</feature> </features> <image src="/images/aa0003.gif" alt="dummy.gif"/> <model src="/models/aa0003.pdb"/> </entry> 

i xml.etree kind of task. supposing xml example has multiple entry records inside other element, used xml file test code:

<records> <entry id="aa0003"> <header> <code>aa0003</code> </header> <names> <name>l-asparagine</name> <alternatename>2,4-bis(azanyl)-4-oxobutanoic acid</alternatename> <alternatename>2,4-diamino-4-oxobutanoic acid</alternatename> </names> </entry> <entry id="??????"> <header> <code>??????</code> </header> <names> <name>n-acetylglucosamine</name> </names> </entry> </records> 

here code parse xml file:

from xml.etree import elementtree  tree=elementtree.parse('residues.xml') entry in tree.findall('entry'):     print entry.find('names/name').text 

this results in:

l-asparagine n-acetylglucosamine 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)