2017-06-13 131 views
-3

我仍在嘗試爲一個賦值創建一個代碼,但遇到了一個空閒問題,告訴我object()不帶參數,但是在代碼中根本沒有對象()。對象()在代碼中沒有參數但沒有對象()

_world = {} 
starting_position = (0, 0) 

def load_tiles(): 
    """Parses file describing the world space in the _world object""" 
    with open("map.txt", 'r') as f: 
     rows = f.readlines() 
    x_max = len(rows[0].split('\t')) # believes all rows contains same amount of tabs 
    for y in range(len(rows)): 
     cols = rows[y].split('\t') 
     for x in range(x_max): 
      tile_name = cols[x].replace('\n', '') 
      if tile_name == 'StartingRoom': 
       global starting_position 
       starting_position = (x, y) 
      _world[(x, y)] = None if tile_name == '' else getattr(__import__('tiles'), tile_name)(x, y) 

def tile_exists(x, y): 
    return _world.get((x, y)) 
+1

你可以顯示完整的跟蹤? – Arun

+0

我很愚蠢。你什麼意思? – liam

+0

控制檯上印有什麼? – Arun

回答

0

老實說,它看起來像你對我不明白你自己的代碼非常好,這就是爲什麼你得到downvoted。您尚未發佈所有代碼。關鍵在函數getattr(__import__('tiles'), tile_name)(x, y) - 你試圖將變量x,y傳遞給(我認爲)一個不期待任何變量的對象。這就是你需要理解的,使用該方法的正確方法。

祝你好運。