[Tutor] identifying and parsing string in text file
marc.tompkins at gmail.com
Sat Mar 8 22:21:52 CET 2008
Sure sounds like XML to me... I'm just snatching a moment from Saturday
chores to type this, but there are a bunch of modules available for XML
manipulation - elementtree is built-in; I personally prefer Amara - and I'll
bet that a few minutes spent with the docs for either module will tell you
what you need to know.
On Sat, Mar 8, 2008 at 11:31 AM, Bryan Fodness <bryan.fodness at gmail.com>
> I have a large file that has many lines like this,
> <element tag="300a,0014" vr="CS" vm="1" len="4"
> I would like to identify the line by the tag (300a,0014) and then grab the
> name (DoseReferenceStructureType) and value (SITE).
> I would like to create a file that would have the structure,
> DoseReferenceStructureType = Site
> Also, there is a possibility that there are multiple lines with the same
> tag, but different values. These all need to be recorded.
> So far, I have a little bit of code to look at everything that is
> for line in open(str(sys.argv)):
> i_line = line.split()
> if i_line:
> if i_line == "<element":
> a = i_line
> b = i_line
> print "%s | %s" %(a, b)
> but do not see a clever way of doing what I would like.
> Any help or guidance would be appreciated.
> "The game of science can accurately be described as a never-ending insult
> to human intelligence." - João Magueijo
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor