Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. def conv_ascii(text,context):
  2.     """Convierte vocales accentuadas, ñ y ç a sus caracteres equivalentes ASCII"""
  3.     old_chars = ['á','é','í','ó','ú','à','è','ì','ò','ù','ä','ë','ï','ö','ü','â','ê','î', \
  4.         'ô','û','Á','É','Í','Ú','Ó','À','È','Ì','Ò','Ù','Ä','Ë','Ï','Ö','Ü','Â','Ê','Î',\
  5.         'Ô','Û','ñ','Ñ','ç','Ç','ª','º', chr(176), chr(0xb0)
  6.     ]
  7.     new_chars = ['a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','a','e','i','o',\
  8.         'u','A','E','I','O','U','A','E','I','O','U','A','E','I','O','U','A','E','I','O','U','n',\
  9.         'N','c','C','a','o', 'o','o'
  10.     ]
  11.     print "contexxxxxxxxxxxxxxrt",context
  12.     print "...............", text
  13.     for old, new in zip(old_chars, new_chars):
  14.         try:
  15.             text = text.replace(unicode(old,'UTF-8'), new)
  16.         except:
  17. #            text = text.replace(old, new)
  18. #            text = "ERROR DE CODIFICACION ID"
  19.             print "...............", text
  20.     return text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement