0

PE¥A, HUMBERTO J., 86, of Miami, Florida passed away Tuesday, July 7, 2015 at home after a long illness. He is survived by his loving wife Sharon, children, Cristy and Jorge, stepson Carson, seven grandchildren and was predeceased by a son, Humberto. He is also survived by Angelita Barcena and his brother Antonio Pe¤a. He will be missed by all, especially by his beloved Dachshund, Barna. Visitation will be from 7:00-10:00 pm July 9, 2015 at Caballero-Rivero Westchester. Funeral Mass to be held at St. Kevin's Catholic Church, Friday July 10, 2015 at 10:30 am. Internment to follow. In Lieu of flowers, the family suggests donations in his name to The Jos‚ Mart¡ Foundation.

I want to insert this para into a csv file

// notice = above para //content.text = a_name
        try:
            a_writter.writerows([[content.text, url, notice]])
        except UnicodeEncodeError:
            try:
                notice = unidecode(notice.encode('utf-8'))
                a_writter.writerows([[content.text, url, notice]])
            except UnicodeEncodeError:
                content_text_encoded = unidecode(content.text.encode('utf-8'))
                a_writter.writerows([[content_text_encoded, url, notice]])

But still instead of

"PE¥A, HUMBERTO J."

it prints

"PEY=A, HUMBERTO J."

How to get the exact encoding as the above notice?

**unidecode https://pypi.python.org/pypi/Unidecode

M.A.K. Simanto
  • 634
  • 1
  • 7
  • 20
  • possible duplicate of [Read and Write CSV files including unicode with Python 2.7](http://stackoverflow.com/questions/17245415/read-and-write-csv-files-including-unicode-with-python-2-7) – Kobi K Jul 14 '15 at 11:42
  • what is `content.text`, `url`, `notice` for the row that causes the exception? – jfs Jul 14 '15 at 18:42
  • `notice = notice.encode('utf8')` → That's kind of weird. That reader interface expects either a `string` or `unicode` type, I'd expect it's pointless to try both. (the built-in csv module expects string). How did you load the paragraph into your program? – roeland Jul 15 '15 at 02:20
  • @KobiK no answer was selected as correct from your link. – M.A.K. Simanto Jul 15 '15 at 09:30
  • Sebastian edited, thanks. @roeland I got the paragraph from soup.find(class_='class_name') with help of BeautifulSoup – M.A.K. Simanto Jul 15 '15 at 09:40
  • 1
    Converting `"PE¥A"` to `"PEY=A"` is ecpected behaviour of unidecode. – roeland Jul 15 '15 at 21:58

0 Answers0