导航:首页 > 编程语言 > python解析doc

python解析doc

发布时间:2022-07-26 09:29:42

python doc文件怎么打开

使用python idld的时候按F1就是,否则直接到python安装目录下doc文件夹下打开文件

㈡ 如何在 Linux 上使用 Python 读取 word 文件信息

第一步:获取doc文件的xml组成文件

import zipfiledef get_word_xml(docx_filename):
with open(docx_filename) as f:
zip = zipfile.ZipFile(f)
xml_content = zip.read('word/document.xml')
return xml_content

第二步:解析xml为树形数据结构
from lxml import etreedef get_xml_tree(xml_string):
return etree.fromstring(xml_string)

第三步:读取word内容:
def _itertext(self, my_etree):
"""Iterator to go through xml tree's text nodes"""
for node in my_etree.iter(tag=etree.Element):
if self._check_element_is(node, 't'):
yield (node, node.text)def _check_element_is(self, element, type_char):
word_schema = '99999'
return element.tag == '{%s}%s' % (word_schema,type_char)

㈢ 如何正确认识Python 源文件

该任务会递归遍历所有的子目录,并编译所有的 Python 模块。脚本中没有采用将 src 目录硬编码到调用之处的方式,而是在构建脚本中定义了称为 src.dir 的属性。然后,在需要使用这个目录名的时候。就可以通过 ${src.dir} 来引用。 要运行构建脚本,可从 Eclipse 中打开它。Eclipse 具有内置的 Ant 构建脚本编辑和浏览功能。Outline 视图可以显示出构建脚本的结构。在 Navigator 视图中。选择该构建脚本,用右键点击,然后选择“Run Ant...”。选择 compile 目标,然后点击“Run”。构建脚本执行过程中的输出信息应该显示在 Console 视图中,表示运行成功。 从对上述 pydoc 目标的解析可看出。对Python编程技巧大总结对于Python设计语言特性进行全解析简读灵活性的Python编程语言有关Python版本大杂烩如何掌握Python异常处理问题第7 行声明了目标名称,并指出它依赖于 init 和 compile 目标。这意味着在运行 pydoc 目标之前,Ant 必须保证 init 和 compile 目标已经运行,如果没有,则首先运行这两个目标。 pydoc 目标所依赖的 init 目标在第 3 至第 5 行定义。 init 目标仅仅创建了一个存放 PyDoc API 文档文件的目录。如前所述,要为所生成文档的保存位置定义一个属性,名为 pydoc.dir。 第8 行开始是 py-doc 任务。如前所述,您传入生成 pydoc 过程中所使用的 PYTHONPATH 。 destdir 属性告诉 py-doc 任务将生成的 HTML 文档输出到何处。 第 9 至第 11 行定义了在生成文档的过程中应该处理哪些 Python 源文件。文件集是 Ant 脚本中通用的结构。可用于定义所操作的一组文件。这是一种很强大的特性,它使您能够通过名字模式、布尔逻辑和文件属性来选择所要操作的文件。Ant 文档中有这方面的完整描述。本例中递归选择了“src”目录下的所有文件。 Python 源文件中具有标准的单元测试框架(从 Python 2.3 开始。在 Python 2.2 中这只是可选模块),与 Java jUnit 框架十分类似。测试用例的结构与 jUnit 采用相同的方式。每一个待测试的类和模块通常都具有自己的测试类。测试类中包含测试装置(fixture)。它们在 setUp 函数中初始化。每一个测试都编写为测试类中的一个独立的测试函数。unittest 框架会在测试函数之间循环往复,先调用 setUp 、再测试函数、然后清除( tearDown )测试函数。请参阅清单 4 中的样例。 import unittest from pprint import pprint import feedparser class FeedparserTest(unittest.TestCase): """ A test class for the feedparser mole. """ def setUp(self): """ set up data used in the tests. setUp is called before each test function execution. """ self.developerWorksUrl = "testData/developerworks.rss" def testParse09Rss(self): """ Test a successful run of the parse function for a 0.91 RSS feed. """ print "FeedparserTest.testParse09RSS()" result = feedparser.parse(self.developerWorksUrl) pprint(result) self.assertEqual(0, result['bozo']) self.assert_(result is not None) channel = result['channel'] self.assert_(channel is not None) chanDesc = channel['description'] self.assertEqual(u'The latest content from IBM developerWorks', chanDesc) items = result['items'] self.assert_(items is not None) self.assert_(len(items)> 3) firstItem = items[0] title = firstItem['title'] self.assertEqual(u'Build installation packages with solution installation and deployment technologies', title) def tearDown(self): """ tear down any data used in tests tearDown is called after each test function execution. """ pass if __name__ == '__main__': unittest.main() 上述清单是实现 feedparser 模块基本测试功能的测试类。完整的测试类见 feedParserTest 项目下的 src/feedparserTest/FeedparserTest.py。step 函数负责准备整个测试过程中需要使用的测试装置,在本例中只有测试用的 RSS 文件的目录。测试函数将对其进行解析。testParse09Rss 是真正的测试函数。Python 源文件这个函数调用 feedparser.parse 函数,传递测试用的 RSS 文件,输出解析结果,并通过 TestCase 类的 assert 函数执行基本的检查统作。如果任何 assert 的求值结果不是真,或是在执行过程中抛出任何异常,unittest 就会报告一次测试失败或错误。最后的两行负责在这个测试类内部运行测试,方法是直接运行该模块即可。

㈣ python中的_doc_是什么

文档字符串。注意,是 __doc__ ,前后各两个下划线。

一般而言,是对函数/方法/模块所实现功能的简单描述。但当指向具体对象时,会显示此对象从属的类型的构造函数的文档字符串。(示例见以下 a.__doc__)

>>> str.__doc__
"str(string[, encoding[, errors]]) -> str\n\nCreate a new string object from the given encoded string.\nencoding defaults to the current default string encoding.\nerrors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."

>>> import math
>>> math.__doc__
'This mole is always available. It provides access to the\nmathematical functions defined by the C standard.'

>>> a = [1]

>>> a.count.__doc__
'L.count(value) -> integer -- return number of occurrences of value'
>>> a.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

为自定义的函数创建 __doc__ 的方法示例:

>>> def func():
"""Here's a doc string"""
pass
>>> func.__doc__
"Here's a doc string"

更详细的资料请参考 Python Tutorial 4.7.6 Documentation Strings.

㈤ 如何用Python实现doc文件批量转换为docx

有一批pdf文件,好几百个,每个只打印第2,3页,双面打印。
网上搜索一波,方案如下:
安装Ghostscript,GhostView,使用gsprint命令打印pdf文件。
gsprint命令参数说明:
"-dQUIET", 安静的意思,指代执行过程中尽可能少的输出日志等信息。(也可以简写为“-q”)
"-dNOSAFER", 通过命令行运行
"-dBATCH", 执行到最后一页后退出
"-dNOPAUSE", 每一页转换之间没有停顿
"-dNOPROMPT", 没有相关提示
"-dFirstPage=1", 从第几页开始
"-dLastPage=5", 到第几页结束
"-sDEVICE=pngalpha", 转换输出的文件类型装置,默认值为x11alpha
"-g720x1280", 图片像素(-gx),一般不指定,使用默认输出
"-r300", 图片分辨率(即图片分辨率为300dpi),默认值好像是72(未测试证实)
"-sOutputFile=/opt/shanhy/error1png/%d.png", 图片输出路径,使用%d或%ld输出页数
比如打印c.pdf第2,3页,命令如下
gsprint -dFirstPage=2 -dLastPage=3 c.pdf
大部分pdf只打印第2,第3页,双面打印,所以用python控制批量打印所有pdf的第二页,暂停,提示翻页,然后批量打印第三页。
完整代码如下
#-*- coding: utf-8 -*-
importosimporttimedefprint_pdf(pdf_file_name, page):"""静默打印pdf
:param pdf_file_name
:page 打印第几页
:return:"""cmd= 'gsprint -dFirstPage=%s -dLastPage=%s %s' %(page, page, pdf_file_name)print(cmd)
p=os.popen(cmd)
time.sleep(3)print(p.read())if __name__ == '__main__':
curr_path=os.getcwd()
fl=os.listdir(curr_path)for i in range(2,4):print(i)for f infl:if 'pdf' inf.lower():
print_pdf(f, i)

㈥ python读取word文档内容

import fnmatch, os, sys, win32com.client

readpath=r'D:\123'

wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
for path, dirs, files in os.walk(readpath):
for filename in files:
if not fnmatch.fnmatch(filename, '*.docx'):continue
doc = os.path.abspath(os.path.join(path,filename))
print 'processing %s...' % doc
wordapp.Documents.Open(doc)
docastext = doc[:-4] + 'txt'
wordapp.ActiveDocument.SaveAs(docastext,FileFormat=win32com.client.constants.wdFormatText)
wordapp.ActiveDocument.Close()
finally:
wordapp.Quit()
print 'end'

f=open(r'd:\123\test.txt','r')
for line in f.readlines():
print line.decode('gbk')
f.close()

㈦ python如何读取word文件

>>>defPrintAllParagraphs(doc):
count=doc.Paragraphs.Count
foriinrange(count-1,-1,-1):
pr=doc.Paragraphs[i].Range
printpr.Text


>>>app=my.Office.Word.GetInstance()
>>>doc=app.Documents[0]
>>>PrintAllParagraphs(doc)

1.什么是域

域应用基础

>>>
@staticmethod
defGetInstance():
u'''获取Word应用程序的Application对象'''
importwin32com.client
returnwin32com.client.Dispatch('Word.Application')
  1. my.Office.Word.GetInstance的方法实现如上,是一个使用win32com操纵Word Com的接口的封装

  2. 所有Paragraph即段落对象,都是通过Paragraph.Range.Text来访问它的文字的

㈧ 如何使用python或R或c或dos命令,获取docx或doc格式文档的字数信息

在windows下你可以调用win32com.client来读取doc文件,然后导出text到变量,用count来统计字数。但结果肯定跟Word统计的字数不一样。

㈨ python 怎么解析f12doc

不同于其他网站的网页(是通过按钮进入下一页或者其它页,这种网站可以清楚看到每个网页的网址信息),需要自己找网页链接,可以通过chrome浏览器自带的开发者工具或者fiddler软件抓包;我们按F12打开工具,按F5刷新,下拉到加载更多处点击!

阅读全文

与python解析doc相关的资料

热点内容
郭天祥单片机实验板 浏览:599
服务器有什么危害 浏览:256
饥荒怎么开新的独立服务器 浏览:753
文件夹变成了 浏览:560
linuxpython绿色版 浏览:431
怎么下载小爱同学音箱app 浏览:554
python占位符作用 浏览:76
javajdbcpdf 浏览:543
php网页模板下载 浏览:192
python试讲课pygame 浏览:409
安居客的文件夹名称 浏览:677
家里服务器如何玩 浏览:451
网站源码使用视频 浏览:748
stc89c52单片机最小系统 浏览:452
邮件安全证书加密 浏览:416
云服务器如何访问百度 浏览:279
常州电信服务器dns地址 浏览:839
用小方块制作解压方块 浏览:42
图像压缩编码实现 浏览:68
特色功能高抛低吸线副图指标源码 浏览:71