Seite 1 von 1

Re: odt- in txt-Format umwandeln

Verfasst: Mittwoch 10. Mai 2017, 17:33
von BlackJack
@nezzcarth: Doch das Modul (`pypandoc`) ist hauptsächlich zum Aufrufen des Programms zum Umwandeln gedacht. Also um es etwas kürzer zu machen als wenn man selbst etwas mit `subprocess` strickt. Dein Shell-Skript in Python:

Code: Alles auswählen

#!/usr/bin/env python
import os
from glob import iglob

import pypandoc


def main():
    for filename in iglob('*.odt'):
        output_filename = os.path.splitext(filename)[0] + '.txt'
        pypandoc.convert_file(filename, 'plain', outputfile=output_filename)


if __name__ == '__main__':
    main()

Re: odt- in txt-Format umwandeln

Verfasst: Mittwoch 10. Mai 2017, 17:41
von nezzcarth
@BlackJack: Alles klar, danke für den Hinweis. Ich habe bisher daraus eigentlich nur convert_text verwendet (zum Beispiel, um in einer Datenbank abgelegte Texte, die HTML enthalten zu konvertieren und extrahieren) und vielleicht zu sehr solche Anwendungszwecke vor Augen.