AttributeError:当dir(模块)指示函数存在时,'module'对象没有属性

时间:2013-06-14 18:28:59

标签: python import

我有一个小的python函数:

def rebuildTilePDB(cost, cols, rows, kept):
    import scripts.domains.tiles as tt
    print dir(tt)
    d = tt.tileDictioanry(cost=cost, rows=rows, cols=cols)
    path = tiles.findTilePDB(d, kept)
    print path

运行它会产生这个:

['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'collections', 'filepaths', 'findTilePDB', 'os', 'tileDictionary', 'tilePDBDictionary']
Traceback (most recent call last):
  File "./domains/pdb_builder.py", line 107, in <module>
    rebuildTilePDB("unit", rows=3, cols=4, kept=[1,2,3,4,5])
  File "./domains/pdb_builder.py", line 83, in rebuildTilePDB
    d = tt.tileDictioanry(cost=cost, rows=rows, cols=cols)
AttributeError: 'module' object has no attribute 'tileDictioanry'

当dir(tt)显示tt模块有一个名为tileDictionary的函数时,我不明白为什么会收到错误。

1 个答案:

答案 0 :(得分:3)

这是一个错字:tt.tileDictioanry必须是tt.tileDictionary