Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12416

Re: Help parsing a text file

Subject Re: Help parsing a text file
From Philip Semanchuk <philip@semanchuk.com>
Date 2011-08-29 14:31 -0400
References <j3glai$1mu$1@dont-email.me>
Newsgroups comp.lang.python
Message-ID <mailman.552.1314642679.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Aug 29, 2011, at 2:21 PM, William Gill wrote:

> I haven't done much with Python for a couple years, bouncing around between other languages and scripts as needs suggest, so I have some minor difficulty keeping Python functionality Python functionality in my head, but I can overcome that as the cobwebs clear.  Though I do seem to keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard).
> 
> I have a text file with XML like records that I need to parse.  By XML like I mean records have proper opening and closing tags. but fields don't have closing tags (they rely on line ends).  Not all fields appear in all records, but they do adhere to a defined sequence.
> 
> My initial passes into Python have been very unfocused (a scatter gun of too many possible directions, yielding very messy results), so I'm asking for some suggestions, or algorithms (possibly even examples)that may help me focus.
> 
> I'm not asking anyone to write my code, just to nudge me toward a more disciplined approach to a common task, and I promise to put in the effort to understand the underlying fundamentals.

If the syntax really is close to XML, would it be all that difficult to convert it to proper XML? Then you have nice libraries like ElementTree to use for parsing.


Cheers
Philip

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help parsing a text file William Gill <noreply@domain.invalid> - 2011-08-29 14:21 -0400
  Re: Help parsing a text file Philip Semanchuk <philip@semanchuk.com> - 2011-08-29 14:31 -0400
    Re: Help parsing a text file William Gill <nospam@domain.invalid> - 2011-08-29 14:56 -0400
  Re: Help parsing a text file Thomas Jollans <t@jollybox.de> - 2011-08-29 23:05 +0200
    Re: Help parsing a text file "Waldek M." <wm@localhost.localdomain> - 2011-08-30 13:50 +0200
  Re: Help parsing a text file Tim Roberts <timr@probo.com> - 2011-08-30 22:37 -0700
  Re: Help parsing a text file JT <james.thornton@gmail.com> - 2011-09-01 10:58 -0700
    Re: Help parsing a text file William Gill <nospam@domain.invalid> - 2011-09-01 14:38 -0400

csiph-web