Aug-18-2021, 06:05 AM
Greetings!
I'm trying to re-open a file if "IF" condition fails.
I'm not sure it is the right thing to do (to reopen the file) and also I'm failing to reopen it for some reason.
I do not have any errors.
Here is the code:
Thank you!
I'm trying to re-open a file if "IF" condition fails.
I'm not sure it is the right thing to do (to reopen the file) and also I'm failing to reopen it for some reason.
I do not have any errors.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from pathlib import Path import io import re for sb in Path( 'D:\\02\\some_logs\\' ).iterdir() : if sb.is_dir() : for esbd in Path(sb).iterdir() : if esbd.is_file() : with io. open (esbd, encoding = 'utf-8' , errors = 'ignore' ) as mfiler: for el in mfiler : el = el.strip() if re.search( "\wLoops\:\s" ,el) : ## Loop string * stuff, nbr = el.split( ':' ) nbr = nbr.strip() if int (nbr) > 1 : pass # Do something here if int (nbr) < = 1 : with io. open (esbd, encoding = 'utf-8' , errors = 'ignore' ) as mfiler: for rel in mfiler : rel = rel.strip() print ( f "{rel}" ) # Do something else |