【发布时间】:2012-04-08 22:07:33
【问题描述】:
properties = ["color", "font-size", "font-family", "width", "height"]
inPath = "style.css"
outPath = "output.txt"
#Open a file for reading
file = open(inPath, 'rU')
if file:
# read from the file
filecontents = file.read()
file.close()
else:
print "Error Opening File."
#Open a file for writing
file = open(outPath, 'wb')
if file:
for i in properties:
search = i
index = filecontents.find(search)
file.write(str(index), "\n")
file.close()
else:
print "Error Opening File."
似乎有效,但是:
- 关键字只搜索一次?
- 它没有写入输出文件。
function takes exactly 1 argument - 我不希望它实际打印索引,而是关键字出现的次数。
非常感谢
【问题讨论】:
标签: python css search count indexing