import binascii LIST= ["3130342e3233372e3134372e3139312038333636206166626434633133","3139322e3234312e3135332e33382038393337203631623461646533"] def sayHello (): f = open(r"d:12.txt","w+") count = 0 for x in LIST: print binascii.unhexlify(x), count = count+1 f.write(binascii.unhexlify(x)) print count f.close() #function sayHello() # call the function