I have a file that looks like this, if docket ="3ghi" (i could be "3ghi" or 5"ghi" )in the file then condition is greater than 4 should be changed to "new" and condition <=2 should be changed to "fair" . I added my code below, the replace command works but my if loop is bad. Please help.
Input:
<code=report docket="3ghi" parse=20>
<items="20" product="abc" condition="9">
<items="50" product="xyz" condition="8">
<items="" product="mno" condition="2">
Output:
<code=report docket="3ghi" parse=20>
<items="20" product="abc" condition="new">
<items="50" product="xyz" condition="new">
<items="" product="mno" condition="fair">
with open(("test.txt",'r') as new:
readin = new.read
if "docket =3ghi" == True:
readin.replace('condition="4-100"', 'condition="new"')
readin.replace('condition="1-2"', 'condition="fair"')
x.write(readin)
True. Use something like"3ghi" in blockxmlwhich is built-in, or a third party package likelxml. Parsers make structured languages like xml and html much easier to process