【发布时间】:2016-05-27 19:52:52
【问题描述】:
我目前正在制作一个使用多个模块运行的游戏。但是,当我尝试运行程序时,模块似乎不起作用。例如,当程序无法识别 main 模块中的函数时。
https://gyazo.com/9d303b12707f5829e084125b76d8cdf9
我预计不会收到上面的错误消息。除此之外,我还想了解绝地是什么。
这是我的代码:
主要(模块):
import jedi
def mains():
jedi = Jedi()
if __name__ == '__main__':
mains()
绝地(模块):
import pygame
class Jedi(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.move_rights = []
self.move_lefts = []
self.image = pygame.image.load("obileft.png")
self.move_lefts.append(self.image)
self.image = pygame.transform.flip(self.image, True, False)
self.move_rights.append(self.image)
self.sprite_x_change = 0
self.sprite_y_change = 0
self.rect = self.image.get_rect()
self.rect.y = 400
self.rect.x = 120
self.nextLevel = False
self.right = False
self.left = False
self.jump = False
self.lightsaberRight = False
self.lightsaberLeft = False
# Mobility: Left, right, up and stop
【问题讨论】:
-
请将其缩减为minimal reproducible example 并解释: 1. 您的预期;和 2. 发生了什么。
-
我的猜测是您应该调用
jedi.Jedi(),因为您正在尝试创建一个Jedi对象,该对象是jedi文件中的一个类。但正如@jonrsharpe 所提到的,没有 MCVE 就很难判断 -
您可以尝试在您的导入中使用 from jedi import Jedi。在 Python stackoverflow.com/questions/6465549/import-paths-the-right-way 中检查此导入
-
我已经编辑了代码,对此很抱歉,但我很少在堆栈溢出。