def trier(): for enc in ['bad','bad2']: try: u'hi'.encode(enc) except LookupError: pass trier() sum(1,0)