无法在类中导入模块

时间:2017-03-17 06:53:13

标签: python

有这个课程:

class Reader24(object):

    import win32com.client


    #def __init__(self):


    def readGenerationFile(self, fileName):
        excel=win32com.client.Dispatch("Excel.Application")
        book=excel.Workbooks.Open(fileName)
        sheet=book.Worksheets('Sheet1')

        row_count = sheet.max_row
        result = []

        for i in range(0,row_count):
            powers = []
            for p in range(4,28):
                powers.append(sheet.Cells(i,p).Value)

            result.append({"id":sheet.Cells(i,1).Value, "name":sheet.Cells(i,2).Value, "volume":sheet.Cells(i,3).Value, "power":powers})

        return result

我使用这样的课程:

import Reader24
reload(Reader24)
from Reader24 import Reader24
read24 = Reader24()
read24.readGenerationFile("D:\USER DATA\New folder\saqme\24_V3\Day balance for 17-March-2017")

我收到错误:

NameError: global name 'win32com' is not defined

我在Python方面比较新,所以我无法弄清楚问题是什么

0 个答案:

没有答案