0

I run the main module, which should work correctly. But an error gets returned. 'spaceship' is not defined when I define 's=spaceship(parameters)' why is this I don't get it. I'm using zelle graphics for python. thank you

Functions from main module:

spaceshipGame file

 from graphics import *
    from spaceshipClass import *

def main():
    window=createGraphicsWindow()
    runGame(window)
    
    
def createGraphicsWindow():
    win=GraphWin("Spaceship game",800,800)
    return win
    
    
def createSpaceship(window,p1,p2,p3,speed,colour):
    s=spaceship(window,p1,p2,p3,speed,colour)
    return s
    
    
    
def runGame(window):
    player=createSpaceship(window,Point(500,500),Point(500,470),Point(520,485),0.5,"red")
    player.draw(window)
    
main()

spaceshipClass file

    from spaceshipGame import *
from graphics import *
class spaceship:
    def __init__(self,window,p1,p2,p3,speed,colour):
        self.p1=p1
        self.p2=p2
        self.p3=p3
        self.speed=speed
        self.colour=colour
        self.window=window
        
Community
  • 1
  • 1
jamie
  • 176
  • 1
  • 12

1 Answers1

1

Never mind, I see the problem. Consult this example for more information:

Simple cross import in python

But the problem is the way you are cross importing, so delete from spaceshipGame import * from spaceshipClass or vise-versa (i.e. delete from spaceshipClass import * from spaceshipGame). You can import individually if you need to like in the example I provided.

There are also many other ways around it if you read the example. One of the easiest would be just merging them in the same file if they need to share a lot of methods.

I Funball
  • 380
  • 1
  • 8