python读取rtf文件_在Python中读取RTF-PyRTF

import sys

sys.path.append( '../' )

from PyRTF import *

SAMPLE_PARA = """The play opens one year after the death of Richard II, and

King Henry is making plans for a crusade to the Holy Land to cleanse himself

of the guilt he feels over the usurpation of Richard's crown. But the

crusade must be postponed when Henry learns that Welsh rebels, led by Owen

Glendower, have defeated and captured Mortimer. Although the brave Henry

Percy, nicknamed Hotspur, has quashed much of the uprising, there is still

much trouble in Scotland. King Henry has a deep admiration for Hotspur and

he longs for his own son, Prince Hal, to display some of Hotspur's noble

qualities. Hal is more comfortable in a tavern than on the battlefield, and

he spends his days carousing with riff-raff in London. But King Henry also

has his problems with the headstrong Hotspur, who refuses to turn over his

prisoners to the state as he has been so ordered. Westmoreland tells King

Henry that Hotspur has many of the traits of his uncle, Thomas Percy, the

Earl of Worcester, and defying authority runs in the family."""

def MakeExample1() :

doc = Document()

ss = doc.StyleSheet

section = Section()

doc.Sections.append( section )

# text can be added directly to the section

# a paragraph object is create as needed

section.append( 'Example 1' )

# blank paragraphs are just empty strings

section.append( '' )

# a lot of useful documents can be created

# with little more than this

section.append( 'A lot of useful documents can be created '

'in this way, more advance formating is available '

'but a lot of users just want to see their data come out '

'in something other than a text file.' )

return doc

def OpenFile(name) :

return file( '%s.rtf' % name, 'w' )

if __name__ == '__main__' :

DR = Renderer()

doc1 = MakeExample1()

DR.Write( doc1, OpenFile( '1' ) )

print('Finished')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值