AttributeError: 'NoneType' object has no attribute
2016-03-03 09:04
916 查看
python 读取excel文件报错:
basetable = data.sheet_by_index(0)
AttributeError: 'NoneType' object has no attribute 'sheet_by_index'
def open_excel(file):
try:
data = xlrd.open_workbook(file)
return data
except Exception as e:
print (e.strerror)
#根据名称获取Excel表格中的数据 参数:file:Excel文件路径 colnameindex:表头列名所在行的所以 ,by_name:Sheet1名称
def excel_table_byname(file= 'C:\python\rename.xlsx',colnameindex=0):
data = open_excel(file)
basetable = data.sheet_by_index(0)
.......
经过调试发现file传进去的时候变成ename.xlsx了。
解决方法:
由单\ 改成双\ 即\\ 即可解决。
basetable = data.sheet_by_index(0)
AttributeError: 'NoneType' object has no attribute 'sheet_by_index'
def open_excel(file):
try:
data = xlrd.open_workbook(file)
return data
except Exception as e:
print (e.strerror)
#根据名称获取Excel表格中的数据 参数:file:Excel文件路径 colnameindex:表头列名所在行的所以 ,by_name:Sheet1名称
def excel_table_byname(file= 'C:\python\rename.xlsx',colnameindex=0):
data = open_excel(file)
basetable = data.sheet_by_index(0)
.......
经过调试发现file传进去的时候变成ename.xlsx了。
解决方法:
由单\ 改成双\ 即\\ 即可解决。
相关文章推荐
- jquery ajax 回调函数的值alert出来[object Object] 解决方法
- Object 的所有方法
- Objective-C-NSObject类的线程方法
- Objective-C-NSOperation
- Objective-C-NSOperation自定义实现
- Objective-C-GCD
- objective-c学习笔记(1)
- 多线程(中) 1.NSThread 2.NSOperationQueue 3.NSObject 4.GCD
- 从C/C++到Objective-C(三)--- 内存管理
- 多线程(NSThread, NSOperationQueue, NSObject,GCD)上
- Objective-C 中的 BOOL
- objective-c中对类别category的理解
- K-means: optimization objective(最小化cost function来求相应的参数)
- 在Objective-C中,字符串的搜索
- iOS中的 多线程- NSThread 与 NSObject
- ActiveXObject 对象 (JavaScript)
- [iOS]编写高质量的Objective-C代码
- Objective-C 中的字符串比较
- Objective-C 和 Core Foundation 对象相互转换的内存管理总结
- JavaScript对象(Object)