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.
JavaScript
x
6
1
from striprtf.striprtf import rtf_to_text
2
from striprtf.striprtf import read_rtf
3
rtf = read_rtf("file.rtf")
4
text = rtf_to_text(rtf)
5
print(text)
6
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?
JavaScript
1
4
1
with open('yourfile.rtf', 'r') as file:
2
text = file.read()
3
print(text)
4
For a super large file, try this:
JavaScript
1
4
1
with open("yourfile.rtf") as infile:
2
for line in infile:
3
do_something_with(line)
4