TypeError:__ init __()取1到4个位置参数,但给出9个

时间:2017-05-05 16:23:41

标签: python-3.5

当我运行以下程序时出现此错误:

with t as ( -- get first 3 names into single array
  select array_agg(name) as first_3_names
  from table_a
  order by id limit 3)
insert into table_b (name1, name2, name3) -- then insert array's elements into the appropriate columns
select first_3_names[1], first_3_names[2], first_3_names[3] from t;

此错误与下面提供的第二个代码源有关。这很奇怪,因为我没有9个参数。我的代码出了什么问题?

 originDataset = dataset.lmdbDataset(originPath, 'abc', *args)
TypeError: __init__() takes from 1 to 4 positional arguments but 9 were given

调用以下程序:

import sys
origin_path = sys.path
sys.path.append("..")
import dataset
sys.path = origin_path
import lmdb

def writeCache(env, cache):
    with env.begin(write=True) as txn:
        for k, v in cache.iteritems():
            txn.put(k, v)

def convert(originPath, outputPath):
    args = [0] * 6
    originDataset = dataset.lmdbDataset(originPath, 'abc', *args)
    print('Origin dataset has %d samples' % len(originDataset))

    labelStrList = []
    for i in range(len(originDataset)):
        label = originDataset.getLabel(i + 1)
        labelStrList.append(label)
        if i % 10000 == 0:
            print(i)

    lengthList = [len(s) for s in labelStrList]
    items = zip(lengthList, range(len(labelStrList)))
    items.sort(key=lambda item: item[0])

    env = lmdb.open(outputPath, map_size=1099511627776)

    cnt = 1
    cache = {}
    nSamples = len(items)
    for i in range(nSamples):
        imageKey = 'image-%09d' % cnt
        labelKey = 'label-%09d' % cnt
        origin_i = items[i][1]
        img, label = originDataset[origin_i + 1]
        cache[labelKey] = label
        cache[imageKey] = img
        if cnt % 1000 == 0 or cnt == nSamples:
            writeCache(env, cache)
            cache = {}
            print('Written %d / %d' % (cnt, nSamples))
        cnt += 1
    nSamples = cnt - 1
    cache['num-samples'] = str(nSamples)
    writeCache(env, cache)
    print('Convert dataset with %d samples' % nSamples)

if __name__ == "__main__":
    convert('/share/datasets/scene_text/Synth90k/synth90k-val-lmdb', '/share/datasets/scene_text/Synth90k/synth90k-val-ordered-lmdb')
convert('/share/datasets/scene_text/Synth90k/synth90k-train-lmdb', '/share/datasets/scene_text/Synth90k/synth90k-train-ordered-lmdb')

0 个答案:

没有答案