I want to convert multiple txt files to docx. I use this code:
from docx import Document
import re
import os
path = 'd://2022_12_02'
direct = os.listdir(path)
for i in direct:
document = Document()
document.add_heading(i, 0)
myfile = open('d://2022_12_02'+i).read()
myfile = re.sub(r'[^\x00-\x7F]+|\x0c',' ', myfile) # remove all non-XML-compatible characters
p = document.add_paragraph(myfile)
document.save('d://2022_12_02'+i+'.docx')
After RUN I get this error:
Traceback (most recent call last):
File "D:\convert txt to docs.py", line 4, in <module>
from docx import Document
File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ModuleNotFoundError: No module named 'exceptions'
>>>
ALSO, in docx module, I see this line underlined with red colour:
from exceptions import PendingDeprecationWarning