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
4
  • 3
    Please cut this down to a minimal reproducible example and explain: 1. what you expected; and 2. what happened instead. Commented May 27, 2016 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 Commented May 27, 2016 at 19:59
  • You could try using from jedi import Jedi in your imports. Check this for imports in Python stackoverflow.com/questions/6465549/import-paths-the-right-way Commented May 27, 2016 at 20:00
  • I have edited the code, sorry about that but I rarely post on stack over flow. Commented May 27, 2016 at 20:05

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand why you can't just 'import jedi' can you please explain this to me?
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.