只是想知道是否有人可以很好地告诉我我做错了什么。处理一些代码,与我的cherrypy项目一起使用
import glob
import os
def get_html(apath):
print (apath)
fhtml = open(apath,'r')
data = fhtml.read()
return data
article_path = os.getcwd() +'/articles/*.html'
myArticles = [glob.glob(article_path)]
print len(myArticles)
for items in myArticles:
get_html(items)
结果是:
['/home/sd/Documents/projects/cherryweb/articles/Module 5-Exploitation Techniques And Exercise.pdf.html']
Traceback (most recent call last):
File "fntest.py", line 22, in <module>
get_html(items)
File "fntest.py", line 10, in get_html
fhtml = open(apath,'r')
TypeError: coercing to Unicode: need string or buffer, list found
我假设它是因为我传递的文件名具有字符串列表中的 [' 和 '],我可以编写一个函数来修剪这些部分,但这是唯一的选择,或者我在做一些愚蠢的事情。
谢谢