【问题标题】:error: " type object 'world_load' has no attribute 'split' "错误:“类型对象'world_load'没有属性'split'”
【发布时间】:2017-08-08 22:46:25
【问题描述】:

我尝试制作游戏,但我无法让世界负载正常工作 反刍的手指 var 更新用于 while 循环 错误出现在块被 pikt 显示出来的区域。

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])

这不是漏洞代码 听到的是错误提示:

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'

【问题讨论】:

    标签: python


    【解决方案1】:

    首先,您的问题很难阅读,因为您使用了糟糕的语法和拼写。其次,python 中的.split() 函数用于将字符串拆分为数组(列表)。您可能正在尝试拆分自己的类,该类不是字符串并且不起作用。或者你可能试图在你的类中调用 split 函数(这是 Python 认为你正在尝试做的事情)并且也不会工作,因为没有 split 函数。目前还不清楚你在问什么。我建议您将这个问题改写为更高的标准,然后人们将更有能力提供帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      相关资源
      最近更新 更多