I'm using os.walk
to search a html file, but it took 2 minutes to return the file.
Any suggestion to improve the performances?
path1 = "//ggco/kk"
shp_list = []
for dirpath, dirnames, y in os.walk(path1):
for k in y:
k.startswith(Lot_Operation_combine) and k.endswith(".html")
fullpath = os.path.join(dirpath, k)
shp_list.append(fullpath)
if os.path.isfile(fullpath):
path = "//ggco/kk"
shp_list = []
for dirpath, dirnames, x in os.walk(path):
for f in x:
if f.startswith(Lot_Operation_combine1) and f.endswith(".html"):
fullpath = os.path.join(dirpath, f)
shp_list.append(fullpath)
if os.path.isfile(fullpath):
with open(fullpath, 'r')as f:
f_contens = f.read()
print(f_contens)
kau = f_contens
context = {"Final": kau}
return render(request, 'Output.html', context)
else:
path = "//ggco/kk"
shp_list = []
for dirpath, dirnames, x in os.walk(path):
for f in x:
if f.startswith(Lot_Operation_1A) and f.endswith(".html"):
fullpath = os.path.join(dirpath, f)
shp_list.append(fullpath)
if os.path.isfile(fullpath):
with open(fullpath, 'r')as f:
f_contens = f.read()
print(f_contens)
kau = f_contens
context = {
"Final": kau
}
return render(request, 'Output.html', context)
I'm new in python programming language.
Have you any idea of using os.walk
to search 1 specific file with better performance?
I hope you guys can share some idea for this problem.
Thank you.