2

I am currently making a game which uses multiple modules to run. However when I try to run the program the modules do not seem to work. And example of this is when the program doesn't recognise functions from modules in main.

https://gyazo.com/9d303b12707f5829e084125b76d8cdf9

I expected to not recieve to not recieve the error message from above. As well as this I wanted to recognise what jedi is.

Here is my code:

Main(Module):

import jedi


def mains():
    jedi = Jedi()


if __name__ == '__main__':
    mains()

Jedi(module):

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
Fabmaur
  • 123
  • 2
  • 12
  • 3
    Please cut this down to a [mcve] and explain: 1. what you expected; and 2. what happened instead. – jonrsharpe May 27 '16 at 19:54
  • my guess is that you should be calling `jedi.Jedi()` since you are attempting to create a `Jedi` object, which is a class as part of the `jedi` file. but as @jonrsharpe mentioned, it is hard to tell without an MCVE – R Nar May 27 '16 at 19:59
  • You could try using from jedi import Jedi in your imports. Check this for imports in Python http://stackoverflow.com/questions/6465549/import-paths-the-right-way – mvidovic May 27 '16 at 20:00
  • I have edited the code, sorry about that but I rarely post on stack over flow. – Fabmaur May 27 '16 at 20:05

1 Answers1

1

You need to import the class in a correct way. For example:

from package.module import class

in your case from jedi import Jedi

mvidovic
  • 321
  • 5
  • 9
  • I don't understand why you can't just 'import jedi' can you please explain this to me? – Fabmaur May 27 '16 at 20:39
  • 3
    `jedi` is the name of the module you're importing from. `Jedi` is the name of a specific class defined in that module. Python has two different ways to import: `import [module]` or `from [module] import [thing]`. If you use the first, you import everything from the module, but when you use the stuff you've imported, you have to specify what module it comes from (so in your example, you would have to call the Jedi class with `jedi.Jedi`). If you use the second way, you only import the specific bit of the module you ask for, but you can use it without naming the module (so, just `Jedi`). – A_S00 May 27 '16 at 20:50