6

I have several hundred .rtf files that need to be converted to .txt.

I have tried reading and writing the contents of the files into a new text file, but this seems rather tedious.

Is there an easier way to do this with python 3?

The data in the .rtf files is formatted as a table, and I need to convert it into one long list in the .txt file.

m4148
  • 61
  • 1
  • 3
  • are you only looking for a change of file extension only? If so doing it in bash/cmd is probably easiest. Can be done in python as well of course, plenty of examples around to list/loop over files in a directory, as well as examples of how to rename files with help of python. – ahed87 Dec 07 '17 at 16:12
  • Possible duplicate of [Is there a Python module for converting RTF to plain text?](https://stackoverflow.com/questions/1337446/is-there-a-python-module-for-converting-rtf-to-plain-text) – Lycopersicum Dec 07 '17 at 19:29
  • Did you find an answer to this? – becko Nov 16 '18 at 13:56
  • @becko I did not, I ended up just doing it manually. – m4148 Dec 07 '18 at 18:49
  • 1
    checkout https://www.gnu.org/software/unrtf/. It's not Python though. – becko Dec 07 '18 at 19:15

1 Answers1

7

I found this package: striprtf, it helped me. Sample usage from the docs:

from striprtf.striprtf import rtf_to_text
rtf = "some rtf encoded string"
text = rtf_to_text(rtf)
print(text)
Dos
  • 1,940
  • 1
  • 25
  • 30