Invalid syntax on single quotes

Question:

I’m working on a text adventure game and wanted to play a sound when you get a game over. I’m using PyGame to do this but it gives me an invalid syntax error on the last single quote when I try to load the sound file. here is the code:

import pygame
import time
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
snd_dir = path.join(path.dirname (_Dog-Walking-Simulator_) 'Game_Over_Yeah.wav')
Asked By: Darkpikachu06

||

Answers:

There’s a couple things wrong,

  • _Dog-Walking-Simulator_ is not a valid variable name (dashes aren’t allowed). But even if it were a valid variable name, it’s not defined. Perhaps you meant __file__?
  • path is not imported: from os import path needs to be added to the imports at the top
  • There’s no comma separating the parameters passed to path.join: path.join(path.dirname(__file__), 'Game_Over_Yeah.wav')
Answered By: Brian
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.