While running this code i am getting error "Local variable "Files" referenced before assignment". I am thinking the scope of variable Files is limited to the IF block. Any suggestions?
import shutil
import os
import logging
import time
import re
timestr = '_'+time.strftime("%Y%m%d-%H%M%S")
logging.basicConfig(filename =
"//p4products//nemis2//filehandlerU//ENSUBAPP_log//ENSUBAPP.log"+timestr, level = logging.INFO,
format = '%(asctime)s:%(levelname)s:%(message)s')
src_dict = "//p4products/nemis2"
pattern = re.compile ("Ena3s5npf_g")
def Search_String_File(src_dict,pattern):
for x in os.listdir(src_dict):
print(x)
if os.path.isfile(os.path.join(src_dict, x)):
files = os.path.join(src_dict,x)
strng = open(files)
for lines in strng.readlines():
try:
if re.search(pattern, lines):
print (re.split(r'=', lines))
except Exception as e:
print(e)
pass
elif x != "ENSUBAPP_search.py":
return Search_String_File(files,pattern)
Search_String_File(src_dict,pattern)
Aucun commentaire:
Enregistrer un commentaire