0

このループを正しく記述する方法を解決できません。90% 完了していますが、これを解決できません。

string.replace(archive_header, "titlefixed", titlefixed)

これは、この for ループに含める必要があります

for arfosers in archive_header, forum_header, search_header, rss_header:
    arfosers.write(rss_header + string.replace(footer_p, "<!-- recent posts -->", postgroup))
    arfosers.close()

(「rssヘッダーのarfosers.write行を取り除くのを手伝ってください)」

これらは、「for」ループで実行したい行です。

archive_header = string.replace(archive_header, "titlefixed", titlefixed)
archive_file.write(archive_header + archive_body + string.replace(footer_p, "<!-- recent posts -->", postgroup))
archive_file.close()

forum_header = string.replace(forum_header, "titlefixed", titlefixed)
forum_file.write(forum_header + string.replace(footer_p, "<!-- recent posts -->",     postgroup))
forum_file.close()

search_header = string.replace(search_header, "titlefixed", titlefixed)
search_file.write(search_header + string.replace(footer_p, "<!-- recent posts -->", postgroup))
search_file.close()

rss_header = string.replace(rss_header, "titlefixed", titlefixed)
rss_file.write(rss_header + string.replace(footer_p, "<!-- recent posts -->", postgroup))
rss_file.close()
4

3 に答える 3

2

私が知っているように、各構造要素は読み取り専用です。インデックス付きの for ループを試してください。

于 2013-08-21T06:25:45.690 に答える
1

このようなもの?

data = (
    (archive_file, archive_header, archive_body),
    (forum_file, forum_header, forum_body),
    (search_file, search_header, search_body),
    (rss_file, rss_header, rss_body)
)

for file, header, body in data:
    header = string.replace(header, "titlefixed", titlefixed)
    file.write(header + body + string.replace(footer_p, "<!-- recent posts -->", postgroup))
    file.close()
于 2013-08-21T06:27:50.950 に答える
1
lStuff = [
        (archive_header,archive_file), 
        (forum_header,forum_file), 
        (search_header,search_file), 
        (rss_header,rss_file)
        ]
for header,file in lStuff:
    header = string.replace(header, "titlefixed", titlefixed)
    file.write(header + string.replace(footer_p, "<!-- recent posts -->",postgroup))
    file.close
于 2013-08-21T06:29:29.753 に答える