Чтение RTF в Python - PyRTF - PullRequest
       12

Чтение RTF в Python - PyRTF

0 голосов
/ 04 июня 2018

Мне нужно прочитать некоторые файлы .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).Может кто-нибудь сказать мне, что я делаю не так?

...