Spaces:
Sleeping
Sleeping
import json | |
from docx import Document | |
def open_file(filepath): | |
with open(filepath, 'r', encoding='utf-8') as infile: | |
return infile.read() | |
def save_file(filepath, content): | |
with open(filepath, 'w', encoding='utf-8') as outfile: | |
outfile.write(content) | |
def append_file(filepath, content): | |
with open(filepath, 'w', encoding='utf-8') as outfile: | |
outfile.write(content) | |
def read_word_document(filepath): | |
try: | |
doc = Document(filepath) | |
paragraphs = [p.text for p in doc.paragraphs] | |
return paragraphs | |
except Exception as e: | |
print(f"Error reading the Word document: {e}") | |
return [] |