作者:乔山办公网日期:
返回目录:office365
使用Python的内来部方法open()读取源文本文件
try:
f=open('/file','r')
print(f.read())
finally:
if f:
f.close()
如果读取word文档推百荐使用第三方度插件,python-docx 可以在官知网上下载
使用方道式
# -*- coding: cp936 -*-
import docx
document = docx.Document(文件路径)
docText = '\n\n'.join([
paragraph.text.encode('utf-8') for paragraph in document.paragraphs
])
print docText
>>> def PrintAllParagraphs(doc):
count=doc.Paragraphs.Count
for i in range(count-1,-1,-1):
pr=doc.Paragraphs[i].Range
print pr.Text
>>> app=my.Office.Word.GetInstance()
>>> doc=app.Documents[0]
>>> PrintAllParagraphs(doc)
1.什么是域
域应用基础
>>>
@staticmethod
def GetInstance():
u'''获取Word应用程序的Application对象'''
import win32com.client
return win32com.client.Dispatch('Word.Application')
my.Office.Word.GetInstance的方法实现如上,是一个使用win32com操纵Word Com的接口的封装
所有Paragraph即段e799bee5baa6e997aee7ad94e59b9ee7ad94336落对象,都是通过Paragraph.Range.Text来访问它的文字的
看你的mysql当前默认的zhidao存储引擎:
mysql> show variables like '%storage_engine%';
你要看某个表用了什么引擎(在显示内结果里参数engine后面的就容表示该表当前用的存储引擎):
mysql> show create table 表名;
请注意,所有的程序在它们第一行都是#!/usr/bin/env/python,也就是说,我们想要Python的解释器来执行这些脚本。因此,7a64e78988e69d83333如果你想你的脚本具有执行性,请使用chmod +x your-script.py, 那么你就可以使用./your-script.py来执行它了(在本文中你将会看到这种方式)
探索platform模块
platform模块在标准库中,它有很多运行我们获得众多系统信息的函数。让我们运行Python解释器来探索它们中的一些函数,那就从platform.uname()函数开始吧:
>>> import platform
>>> platform.uname()
('Linux', 'fedora.echorand', '3.7.4-204.fc18.x86_64', '#1 SMP Wed Jan 23 16:44:29 UTC 2013', 'x86_64')
如果你已知道linux上的uname命令,那么你就会认出来这个函数就是这个命令的一个接口。在Python 2上,它会返回一个包含系统类型(或者内核版本),主机名,版本,发布版本,机器的硬件以及处理器信息元组(tuple)。你可以使用下标访问个别属性,像这样:
>>> platform.uname()[0]
'Linux'
在Python 3上,这个函数返回的是一个命名元组:
>>> platform.uname()
uname_result(system='Linux', node='fedora.echorand',
release='3.7.4-204.fc18.x86_64', version='#1 SMP Wed Jan 23 16:44:29
UTC 2013', machine='x86_64', processor='x86_64')
因为返回结果是一个命名元组,这就可以简单地通过名字来指定特定的属性,而不是必须记住下标,像这样:
>>> platform.uname().system
'Linux'
platform模块还有一些上面属性的直接接口,像这样:
>>> platform.system()
'Linux'
>>> platform.release()
'3.7.4-204.fc18.x86_64'