![](/img/trans.png)
[英]I got the "AttributeError: 'OutStream' object has no attribute 'buffer'" when i run the below python code that are from w3school in the google colab
[英]I got “AttributeError: World instance has no attribute 'fire' ” while executing below code. what should i do?
class World(DirectObject):
def __init__(self):
..........................
..........................
..........................
if (self.keyMap["fire"] !=0 and task.time > task.nextBullet):
self.fire(task.time,self.panda.getPos(), self.panda.getHpr(), bulletSpeed, bulletLife)
........................
........................
........................
........................
def fire(self, time, pos, hpr, speed, life):
self.node = World.sphere.copyTo(render)
self.node.setPosHpr(pos, hpr)
self.speed = speed
self.life = life
self.alive = True
self.bullets.append(self.node)
return task.cont
w = World()
run()
def fire(...)
与def __init__(...)
处于相同的缩进级别? 如果没有,那就存在问题。
在您发布的代码中, fire
被定义为__init__
方法中的普通函数(恰好将self
作为其第一个参数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.