Hyは一緒に問題を抱えています。私は実際にやりたいことを説明します。私はいくつかのコンテンツを取得し、それをtxtファイルに書いてほしいと思うからphpファイルを含むいくつかのWebページフォルダを持つルートフォルダです。コードは実行され、エラーは出ませんが、必要なコンテンツを含む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