2017-08-08 61 views
-3

我嘗試做一個遊戲但是我無法獲得世界負載工作 cud被gud改爲no var update是爲while循環 錯誤發生在塊得到pikt和displayd的區域。錯誤:「type object'world_load'沒有屬性'split'」

class world_load: 
def __init__(self, line): 
    self.type = line[0] 
    self.x = line[1] 
    self.y = line[2] 
def __str__(self): 
    return self.type+" "+self.x+" "+self.y 


with open(fillName, encoding=encoding) as file: 
    file.readline() 
    for line in file.readlines(): 
     line = line.strip() 
     line = line.split(" ") 
     w = world_load(line) 
     world.append(p) 

while update: 

#input 

for event in pygame.event.get(): 
    if event.type == pygame.QUIT: 


     update = False 




dis.fill(sky) 


for world_load in world: 

    wo = world_load.split(" ") 

    if wo[0] == block_grass: 

     block_grass(wo[1],wo[2]) 

它WOS不是孔代碼 聽到的是錯誤Fing頭:

Traceback (most recent call last): 
File "C:\Users\Deltagare\Desktop\program\Game\Game.py", line 68, in <module> 
wo = world_load.split(" ") 
AttributeError: type object 'world_load' has no attribute 'split' 

回答

0

首先,它是很難讀你的問題,因爲你已經使用的語法差和拼寫。其次python中的.split()函數用於將字符串拆分爲數組(列表)。你可能試圖分裂你自己的類,這不是一個字符串,不會工作。或者您可能試圖在您的類中調用split函數(這是Python認爲您正在嘗試執行的操作),並且由於沒有分割函數而無法工作。目前還不清楚你在問什麼。我建議你將這個問題重寫爲更高的標準,然後人們將能夠更好地提供幫助。

相關問題