Help needed with nested parsing of file into objects

richard pullenjenna10 at gmail.com
Tue Jun 5 17:53:08 EDT 2012


On Jun 5, 10:33 pm, Alain Ketterlin <al... at dpt-info.u-strasbg.fr>
wrote:
> richard <pullenjenn... at gmail.com> writes:
> >> > An instance of TestArray
> >> >  a=a
> >> >  b=b
> >> >  c=c
> >> >  List of 2 A elements:
> >> >   Instance of A element
> >> >    a=1
> >> >    b=2
> >> >    c=3
> >> >   Instance of A element
> >> >    d=1
> >> >    e=2
> >> >    f=3
> >> >  List of 1 B elements
> >> >   Instance of B element
> >> >    a=1
> >> >    b=2
> >> >    c=3
> >> >    List of 2 C elements
> >> >     Instance of C element
> >> >      a=1
> >> >      b=2
> >> >      c=3
> >> >     Instance of C element
> >> >      a=1
> >> >      b=2
> >> >      c=3
>
> [...]
>
> > Hi Alain thanks for the reply. With regards to the missing case "An
> > Instance of" im not sure where/ how that is working as the case i put
> > in originally "Instance of" is in the file and been handled in the
> > previous case.
>
> Both cases are different in your example above. Top level elements are
> labeled "An instance ...", whereas "inner" instances are labeled
> "Instance of ...".
>
> > Also when running the final solution im getting a list of [None, None]
> > as the final stack?
>
> There's only one way this can happen: by falling through to the last
> case of build(). Check the regexps etc. again.
>
> > just busy debugging it to see whats going wrong. But sorry should have
> > been clearer with regards to the format mentioned above. The objects
> > are been printed out as dicts so where you put in
>
> >         elif "An Instance of" in couple[0]:
> >             return dict(couple[1])
>
> >         should still be ?
> >         elif "Instance of" in couple[0]:
> >             match = re.search("Instance of (.+) element", couple[0])
> >             return ("attr_%s" % match.group(1),Stanza(couple[1])) #
> > instantiating new stanza object and setting attributes.
>
> Your last "Instance of..." case is correct, but "An instance..." is
> different, because there's no containing object, so it's probably more
> like: return Stanza(couple[1]).
>
> -- Alain.

A big thank you to everyone who has helped me tackle / shed light on
this problem it is working great. Much appreciated.




More information about the Python-list mailing list