I am a python and pygame noob, looked up a tutorial for loading sprites in to my game, and I'm getting syntax error for this this line of code
    except pygame.error, message:
                   ^
    SyntaxError: invalid syntax
This is the entire block of code:
def load_image(self, image_name):
    try:
        image = pygame.image.load(image_name)
    except pygame.error, message:
        print "Cannot load image: " + image_name
        raise SystemExit, message
    return image.convert_alpha()
I didn't check if the tutorial was for python 3.4.2 or not, has the syntax changed?
Or is there something else wrong with my code?
You have to use as message in python3 and    raise SystemExit(message): 
def load_image(self, image_name):  
    try:
        image = pygame.image.load(image_name)    
    except pygame.error as message:   
        print("Cannot load image: " + image_name)
        raise SystemExit(message)    
    return image.convert_alpha()
Also print is a function in python3 so you need parens.
Writing except pygame.error, message: is only valid in Python 2.  In Python 3, you must instead write:
except pygame.error as message:
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With