How to prefix image processing result with the name of the image in Python? -


def generalarea(self):   filename in glob.iglob ('*.tif'):     img = np.asarray(image.open(filename).convert('l'))                                 img = 1 * (img < 127)     garea = (img == 0).sum()     print garea  def areasplit(self):   filename in glob.iglob ('*.tif'):         img = np.asarray(image.open(filename).convert('l'))                                 img = 1 * (img < 127)     areasplit = np.split(img.ravel(), 24) # here splitting converted 1d array   in areasplit:    sarea = (i == 0).sum()    print sarea 

these 2 methods process .tif images in working directory. need add prefix imagename number result (to like: firstimage, 6786876876 or secondimage___67876876). how implement idea?

for example, first function, instead of print garea, have:

print "%s___%d" % (filename, garea) 

or "%s, %d" if want comma. see python's doc on string formatting operations.