AttributeError:“书”对象没有“保存”属性。在保存文件期间

Posted

技术标签:

【中文标题】AttributeError:“书”对象没有“保存”属性。在保存文件期间【英文标题】:AttributeError: 'Book' object has no attribute 'save'. During save the file 【发布时间】:2016-08-14 14:42:45 【问题描述】:

我是 python(3.5.1) 的初学者。 请有人帮助我。这是代码..

import os
import xlrd
import xlwt
import openpyxl

book = xlwt.Workbook('C:/python3.5')
sheet1 = book.add_sheet("PySheet1") 
sheet1.write(1,1,'anuj')
book.save('temp.xls')

【问题讨论】:

您能否格式化您的代码,将代码缩进 4 个空格或选择所有代码并按 ctrl + k xlwt.readthedocs.io/en/latest/api.html 我认为您不应该使用文件路径调用该构造函数:class xlwt.Workbook.Workbook(encoding=’ascii’, style_compression=0) 【参考方案1】:
#xlrd, xlutils and xlwt modules need to be installed.  
#Can be done via pip install <module>
from xlrd import open_workbook

from xlutils.copy import copy

rb = open_workbook("names.xls")
wb = copy(rb)

s = wb.get_sheet(0)
s.write(0,0,'A1')
wb.save('names.xls')

【讨论】:

以上是关于AttributeError:“书”对象没有“保存”属性。在保存文件期间的主要内容,如果未能解决你的问题,请参考以下文章

AttributeError:“GridSearchCV”对象没有属性“best_estimator_”

AttributeError: 'RDD' 对象没有属性 'show'

AttributeError:“NumpyArrayIterator”对象没有属性“类”

AttributeError:“模块”对象没有属性“WebSocketApp”

AttributeError: 'float' 对象没有属性 'split'

AttributeError:'list' 对象没有属性 'size'