def py2encode(s):
 return (s.encode('utf-8') if (PY2 and (type(s) is unicode)) else s)

def py2encode ( s ) : return ( s . encode ( 'utf-8' ) if ( PY2 and ( type ( s ) is unicode ) ) else s )
encode in python 2 .