I am having a .rtf file and I want to read the file and store strings into list using python3 by using any package but it should be compatible with both Windows and Linux.
I have tried striprtf but read_rtf is not working.
from striprtf.striprtf import rtf_to_text from striprtf.striprtf import read_rtf rtf = read_rtf("file.rtf") text = rtf_to_text(rtf) print(text)
But in this code, the error is: cannot import name ‘read_rtf’
Please can anyone suggest any way to get strings from .rtf file in python3?
Advertisement
Answer
Have you tried this?
with open('yourfile.rtf', 'r') as file: text = file.read() print(text)
For a super large file, try this:
with open("yourfile.rtf") as infile: for line in infile: do_something_with(line)