Hy一起,我有我的代碼問題,因爲它不做它應該做的。我將描述我真正想要做的事情。我有文件夾caled測試是根文件夾與幾個網頁文件夾包含php文件從至極我想獲得一些內容並將其寫入一個txt文件。代碼運行並且不會給出任何錯誤,但它也不會創建帶有我想要的內容的words.txt文件。任何想法爲什麼?Python獲取內容位於不同文件夾中的文件
from __future__ import print_function
import io
import os
import re
rootdir ='.../test' # I write here the full path but due to privacy reassons only the folders name
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file.endswith(".php"):
with io.open(file, encoding="utf-8") as f, io.open('words.txt', 'w',encoding="utf-8") as g:
for line in f:
h = re.sub(r"$slimname = '([^']+)'", r"\1", line.rstrip())
m = re.sub(r"'alwaysfound_text' => '([^']+)'", r"\1", line.rstrip())
l = re.sub(r"'alwaysfound_place' => '([^']+)'", r"\1", line.rstrip())
j = re.sub(r"'alwaysfound_job' => '([^']+)'", r"\1", line.rstrip())
k = re.sub(r"var_keyword_hidden_generic' => '([^']+)'", r"\1", line.rstrip())
print (h, m, l, j, k, file = g)
它現在的作品,非常感謝:D – Vedad