pythond的unable to get repr for <class 'xlwings,main.book'>


def delete_first_row():
    global delete_run_time, cell_num
    print('path', os.listdir(path))
    print(len(os.listdir(path)))
    i = 0
    for filename in os.listdir(path):  # 遍历子目录  这里的filename为当前文件名
        if '.csv' in filename:  # os.path.split(path)[1]:     # 检验文件名里是否包含str_name
            i += 1
            csv_file = os.getcwd() + '\\' + filename
            print('csv_file', csv_file)
            print_log('Deleting first row in '+str(filename)+'\n')
            if 'GtpuStat' in filename:
                for line in fileinput.input(csv_file, inplace=1):
                    if not fileinput.isfirstline():
                        print(line.replace('\n', ''))
                for line in fileinput.input(csv_file, inplace=1):
                    if not fileinput.isfirstline():
                        print(line.replace('\n', ''))
                apl = xw.App(visible=False, add_book=False)
                workbook = apl.books.open(csv_file)
                worksheet = workbook.sheets.active
                rows = worksheet.api.UsedRange.Rows.count
                print(rows)
                worksheet.range('A2').api.EntireRow.Delete()
                worksheet.range('A' + str(rows - 1)).api.EntireRow.Delete()
                workbook.save()
                workbook.close()

如代码所示,我想对含有GtpuStat字符的CSV表格进行删行处理,但是进行到rows = worksheet.api.UsedRange.Rows.count处理时卡住死机,如果关闭程序,则CSV表格会在EXECEL进程中一直运行,除非手动杀掉进程,不然就一直运行。
debug了一下,发现前面的workbook = apl.books.open(csv_file)会报出unable to get repr for <class 'xlwings,main.book'>
以及worksheet = workbook.sheets.active会报unable to get repr for <class 'xlwings,main.sheet'>,这是为什么啊?

顶顶