我把html_output這個(gè)文件修改了下,就提示我AttributeError: 'HtmlOutputer' object has no attribute 'save_excel'
# -*-coding:UTF-8-*-
import xlsxwriter
class HtmlOutputer(object):
? ?def __init__(self): ?# 建立列表存放數(shù)據(jù)
? ? ? ?self.datas = []
? ?def collect_data(self,data): ?# 收集數(shù)據(jù)
? ? ? ?if data is None:
? ? ? ? ? ?return
? ? ? ?self.datas.append(data)
? ?def save_excel(self):
? ? ? ?book = xlsxwriter.Workbook(r'C:\Users\Administrator\Desktop\abc.xlsx') #默認(rèn)儲(chǔ)存在桌面
? ? ? ?tmp = book.add_worksheet() #建立sheet
? ? ? ?row_num = 11 #行號
? ? ? ?for data in self.datas:
? ? ? ? ? ?for i in range(1, 11):
? ? ? ? ? ? ? ?tag_pos1 = 'A%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos1,data['url'])
? ? ? ? ? ? ? ?tag_pos2 = 'B%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos2,data['title'])
? ? ? ? ? ? ? ?tag_pos3 = 'C%s' % i
? ? ? ? ? ? ? ?tmp.write(tag_pos3,data['summary'])
? ? ? ?book.close()
代碼如上,我的類里明明已經(jīng)定義了這個(gè)方法,求大佬指教,我用的是pycharm,第三方模塊已經(jīng)全部導(dǎo)入了
2017-02-19
你的save_excel是方法,先在你調(diào)用的類里面, 把HtmlOutputer這個(gè)對象生成了
self.outputer = html_outputer.HtmlOutputer()
然后 outputer.save_excel()?
注意excel加括號