今天在写代码的时候出现了如下两个错误:python
TypeError: 'module' object is not callable
AttributeError: excelChange instance has no attribute 'xlBook'
上网一查,发现第一个错误是因为python中有两种不一样的引用方式 import xxx 和 from xxx import *,前者在代码中引用时须要加上模块名和具体的方法或属性,具体方法以下:spa
import catchForm self.xls = catchForm.catchForm()
而from xxx import *则能够直接引用:excel
from catchForm import * self.xls = catchForm()
解决完第一个错误后,立刻又遇到了第二个错误,代码以下:code
class excelChange:
"""一个win32com的封装类,将其全部方法封装在内,
统一调用
"""
def _init_(self,filename = None):#传入文件名参数,若是有的话,没有就把None赋值给filename,自个再新建一个
self.xlApp = Dispatch('Excel.Application')
if filename:
self.filename = filename
self.xlBook = self.xlApp.Workbooks.Open(filename)
else:
self.xlBook = self.xlApp.Workbooks.Add()
self.filename = ''
上网一查发现:orm
_init_写错了,正确的写法应该是__init__,有两个下划线blog