mercredi 24 juillet 2019

Python - In a text file, strip a line containing a number greater than a certain value

I have the following code:

with open(rawfile) as f, open(outfile,'w') as f2:
    for x in f:
      if (':') not in x and ('Station') not in x and('--')not in x and('hPa') not in x:
          f2.write(x.strip()+'\n')

The "...if ___ not in x..." lines identify a line containing that string and removes the line while keeping the rest of the text in the same format. I would like to do this same thing, but remove any line containing a number greater than 10000.

Aucun commentaire:

Enregistrer un commentaire