Use Python to read the contents of Doc and docx documents under Ubuntu __python

Source: Internet
Author: User
The package used to read the docx document is Python-docx 1. Install Python-docx Package
sudo pip install Python-docx
2. Read data using Python-docx packet
#encoding: UTF8
import docx
doc = docx. Document (' Test.docx ')
doctext = ' \ n '. Join ([Paragraph.text for paragraph in doc.paragraphs])
#print (DocText)

Python-docx This package is not able to handle DOC documents, you need to use the Antiword tool to read the contents of DOC documents. Reading doc documents 1. Download Antiword to the website. 2. After downloading the decompression, in the extracted folder to run make and make install command. 3. Read Doc document content using Antiword
#encoding: UTF8
import subprocess
word = ' test.doc '
output = Subprocess.check_output ([' Antiword ', Word])
Print (output)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.