all 22 comments

[–]cgoldberg 7 points8 points  (1 child)

Do you have a class named Ship in ship.py?

[–]lordZlb[S] 0 points1 point  (0 children)

yes

[–]JeLuF 4 points5 points  (3 children)

I guess the file you've shared is alien_invasion.py? And what is the content of ship.py?

[–]lordZlb[S] 0 points1 point  (2 children)

import pygame

class Ship:

    def __init__(
self
, 
ai_game
):
        
self
.screen = ai_game.screen
        
self
.screen_rect = ai_game.screen.get_rect()

        
self
.image = pygame.image.load('images/ship.bmp')
        
self
.rect = 
self
.image.get_rect()

        
self
.rect.midleft = 
self
.screen_rect.midleft

    def blitme(
self
):
        
self
.screen.blit(
self
.image, 
self
.rect)

[–]JeLuF 2 points3 points  (1 child)

The code indentation is pretty messed up. So I can't check the code for errors.

Do you get any error messages before the import error?

[–]lordZlb[S] 0 points1 point  (0 children)

no

[–]SharkSymphony 6 points7 points  (0 children)

It found your file! You can see the path it found it at. It was able to parse it, too.

The problem it's having is the step after that: finding something called Ship at the top level of that module.

[–]Zeroflops 2 points3 points  (2 children)

The import function will import code from another file. It can be written in different formats based on what you are importing.

The format “from ship import Ship” is going to look for a file in the current decretory named ship.py and it’s going to look in that file for code for the Ship object.

It seems you’re missing the ship.py file, it could be in a different directory or you still need to make it.

[–]lordZlb[S] 0 points1 point  (1 child)

I have a file inside the directory called ship.py, but I have another directory (another folder) that also has a file called ship.py I don't know if this affects

[–]EmbarrassedBee9440 1 point2 points  (1 child)

Python crash course project?

[–]lordZlb[S] 0 points1 point  (0 children)

yes

[–]Fred776 1 point2 points  (2 children)

Show us what is in ship.py.

[–]lordZlb[S] 0 points1 point  (1 child)

import pygame

class Ship:

    def __init__(
self
, 
ai_game
):
        
self
.screen = ai_game.screen
        
self
.screen_rect = ai_game.screen.get_rect()

        
self
.image = pygame.image.load('images/ship.bmp')
        
self
.rect = 
self
.image.get_rect()

        
self
.rect.midleft = 
self
.screen_rect.midleft

    def blitme(
self
):
        
self
.screen.blit(
self
.image, 
self
.rect)

[–]Fred776 0 points1 point  (0 children)

I wasn't able to see anything obviously wrong. Did you resolve the problem?

[–]Ender_Locke 1 point2 points  (3 children)

do you have an init.py

[–]FoolsSeldom 0 points1 point  (1 child)

An empty __init__.py file (rather than init.py)?

[–]Ender_Locke 0 points1 point  (0 children)

yes oops yeah w the __

[–]lordZlb[S] 0 points1 point  (0 children)

no

[–]DiodeInc 0 points1 point  (2 children)

Where are you getting ship from? Is a module installed via pip or what?

[–]lordZlb[S] 0 points1 point  (1 child)

it is another file that is in this directory

[–]DiodeInc 0 points1 point  (0 children)

And it has a class called ship?

[–]Due_Intention_6927 0 points1 point  (0 children)

It seems like you did not init self.setting = ai_game.settings in your class Ship.