Skip to content

Commit

Permalink
Use template strings rather than dodgy concatenation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Herne committed Nov 25, 2014
1 parent c8339fc commit a987ccd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Map.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ def __init__(self, mapdict):
itemfilepath = os.path.join('map', mapdict['dir'], mapdict['itemfile'])
for filepath in terrainfilepath, itemfilepath:
if not os.path.isfile(filepath):
raise Exception(filepath+" is not a file")
raise Exception("%s is not a file" %filepath)

groundimage = pygame.image.load(terrainfilepath).convert()
groundarray = pygame.surfarray.pixels2d(groundimage)
wronggroundcolours = numpy.setdiff1d(groundarray, terrain.colorlist(groundimage))
if wronggroundcolours.size:
print wronggroundcolours
raise Exception("Unexpected value in "+terrainfilepath)
raise Exception("Unexpected value in %s" %terrainfilepath)
collectablesimage = pygame.image.load(itemfilepath).convert()
collectablesarray = pygame.surfarray.pixels2d(collectablesimage)
collectablescolorsflat = pygame.surfarray.map_array(collectablesimage, numpy.array(collectables.mapcolor.keys()))
wrongcollectablecolors = numpy.setdiff1d(collectablesarray, collectablescolorsflat)
if wrongcollectablecolors.size:
print wrongcollectablecolors
raise Exception("Unexpected value in "+itemfilepath)
raise Exception("Unexpected value in %s" %itemfilepath)
self.size = groundimage.get_rect().size

nbrcount = numpy.zeros(self.size, dtype=numpy.uint)
Expand Down
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

def get(section, name, valuetype, default=None):
try:
value = mainconfig.get(section, name)
if valuetype is bool:
# ConfigParser.getboolean() does useful string parsing.
return mainconfig.getboolean(section, name)
else:
return valuetype(mainconfig.get(section, name))
return valuetype(value)
except ValueError:
if default is None:
raise
else:
print "Warning: invalid value for ["+section+"] '"+name+"'"
print "Warning: invalid value '%s' for [%s], %s" %(value, section, name)
except ConfigParser.Error:
if default is None:
raise
Expand Down
4 changes: 2 additions & 2 deletions images.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def dirsprites(image):
if not os.path.isdir(os.path.join('tiles', 'terrain', name)):
continue
if not (name in terrain.types['groundimage'] or name in terrain.types['topimage']):
print "Warning: terrain sprites", name, "not used"
print "Warning: terrain sprites %s not used" %name
terraingroups[name] = []
for filename in os.listdir(os.path.join('tiles', 'terrain', name)):
filepath = os.path.join('tiles', 'terrain', name, filename)
Expand All @@ -53,7 +53,7 @@ def dirsprites(image):
loadedimage = pygame.image.load(filepath).convert()
numtiles = float(loadedimage.get_width())/loadedimage.get_height()
if numtiles not in [1, 6]:
print "Warning: sprite", filepath, "has invalid size"
print "Warning: sprite %s has invalid size" %filepath
continue
if numtiles == 1:
loadedimage.set_colorkey(MAGENTA, pygame.RLEACCEL)
Expand Down
6 changes: 3 additions & 3 deletions worlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
try:
imfile = open(descfilename)
except:
print "Unable to load map", name+":"
print "File", descfilename, "unreadable or missing"
print "Unable to load map %s name:" %name
print "File %s unreadable or missing" %descfilename
continue
try:
newmap = json.load(imfile)
except ValueError as err:
print "Unable to load map", name+":"
print "Unable to load map %s:" %name
print err
continue
imfile.close()
Expand Down

0 comments on commit a987ccd

Please sign in to comment.