class __init__:
path = "articles/"
files = os.listdir(path)
files.reverse()
def iterate(Files, Path):
def handleXml(content):
months = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
parse = re.compile('<(.*?)>(.*?)<(.*?)>').findall(content)
day = parse[1][1]
month = months[int(parse[2][1])]
dayN = parse[3][1]
year = parse[4][1]
hour = parse[5][1]
min = parse[6][1]
amPM = parse[7][1]
title = parse[9][1]
author = parse[10][1]
article = parse[11][1]
category = parse[12][1]
if len(Files) > 5:
del Files[5:]
for file in Files:
file = "%s%s" % (Path, file)
f = open(file, 'r')
handleXml(f.read())
f.close()
iterate(files, path)
它在启动时运行,如果我检查文件数组,它包含所有文件名。但是当我遍历它们时,它们只是不起作用,只显示第一个。如果我返回文件,我只会得到前两个,如果我返回 parse 即使是重复的文件,它也不相同。这些都没有任何意义。
我正在尝试使用 Python 制作一个简单的博客,因为我的服务器有一个非常旧的 Python 版本,我不能使用像 glob 这样的模块,所以一切都需要尽可能基本。
files 数组包含目录中的所有文件,这对我来说已经足够了。我不需要浏览文章目录中的其他目录。
但是当我尝试输出解析时,即使在重复文件上我也会得到不同的结果。
谢谢,
- 汤姆