我需要读一些.rtf文件,所以我安装了PyRTF。我在网上查看了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')
但是,当我尝试运行代码时,它似乎无法识别导入: ' NameError:name' Renderer'未定义'
我检查了安装,它说我安装了最新版本(0.47.5)。有人能告诉我我做错了吗?