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:
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:
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 elseThank you!