当前位置: 首页 > 工具软件 > Unbound > 使用案例 >

解决Python中TypeError: unbound method 问题

易星宇
2023-12-01


今天执行了下之前写的Python接口文件,源码如下,

__author__ = 'Administrator'
#coding:utf-8
from readData import dictionary
readIt = {}
readIt = dictionary.onlyCellValue("E:\python\API\eadData.xls", "Sheet1", 1)
print readIt
for key in readIt:
    temp_list = readIt[key]
    for i in range(0, len(temp_list)):
        print "第"+(i+1)+"个参数为"+temp_list[i]


在运行时报错:TypeError: unbound method onlyCellValue() must be called with dictionary instance as first argument (got str instance instead)

后经在网上查看,发现时由于调用其他类时,未在后面添加括号,添加括号后,运行正常。这是由于未添加括号情况下,未被认为是类的实例,故报此错

改正后的:readIt = dictionary().onlyCellValue("E:\python\API\eadData.xls", "Sheet1", 1)

 类似资料: