python文件命名时的注意点

   在python中读取Excal文件,需要引用xlrd模块,因此建的这个python文件名为xlrd.py

部分代码如下:

import xlrd

import os

newpath = os.chdir(r'Excal文件所在路径')

filename = ‘Excal文件名’

file = os.join(os.getcwd(),filename)

 

xl = xlrd.open_workbook(file)  #打开文件

table1 = xl.sheet_by_name('某一sheet页的名字')  #获取sheet页内的汇总数据

print table1.cell_value(0,0)  #获取第0行第0列的值

执行程序报"AttributeError: module 'xlrd' has no attribute 'open_workbook'",把python文件名xlrd1.py改为xlrd.py解决此问题

posted on 2018-01-21 17:48  希望的天空  阅读(2309)  评论(0编辑  收藏  举报