#!/usr/bin/python
d = {’spam’:2, ’ham’:1, ’eggs’:10}
print d[’eggs’]
./py13.py 10
d = {}
d[’foobar’] = 4
del d[’eggs’]
#!/usr/bin/python
d = {’spam’:2, ’ham’:1, ’eggs’:10}
if d.has_key(’eggs’):
print ’we have some eggs’
else:
print ’we do not have any eggs’
if d.has_key(’flour’):
print ’we have some flour’
else:
print ’we do not have any flour’
def playSound(sound):
global soundDict
if soundDict.has_key(sound):
soundDict[sound].play()
else:
print "no sound file ", sound, " found"
soundDict = {} # define empty dictionary
def initSounds():
addSound("arrowswish")
addSound("brokenglass")
addSound("fuse")
addSound("evillaugh")
addSound("ohno")
addSound("ohnoexplode")
def addSound(name):
global soundDict
soundDict[name] = load_sound(name + ".wav")
def load_sound(name):
class NoneSound:
def play(self):
pass # pass means { } in C or Java or C++
if not pygame.mixer or not pygame.mixer.get_init():
return NoneSound()
fullname = getFileName(’sounds’, name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print ’cannot load sound file:’, fullname
return NoneSound()
return sound
def getFileName(subdir, filename):
global dataDirectory
if dataDirectory == "":
return os.path.join(subdir, filename)
else:
return os.path.join(dataDirectory,
os.path.join(subdir, filename))
chmod 700 penguin-server ./penguin-server maps/star
This document was produced using groff-1.19.