nghiank09
Thành viên hoạt động



- Tham gia
- 1/3/12
- Bài viết
- 143
- Được thích
- 30
Chào các bạn,
Mình có đoạn code sau, xin các bạn hỗ trợ sửa lỗi. Mình chạy thì báo lỗi re.error: bad escape \R at position 18 ở dòng code
myfile = re.sub(r'^(Dir|\d{2}:|$).*\R',' ', myfile) # remove all non-XML-compatible characters
Cám ơn các bạn
Mình có đoạn code sau, xin các bạn hỗ trợ sửa lỗi. Mình chạy thì báo lỗi re.error: bad escape \R at position 18 ở dòng code
myfile = re.sub(r'^(Dir|\d{2}:|$).*\R',' ', myfile) # remove all non-XML-compatible characters
Mã:
import webvtt
from docx import Document
import re
import os
# path = '/users/tdobbins/downloads/smithtxt'
path = 'D:/A'
direct = os.listdir(path)
for i in direct:
document = Document()
document.add_heading(i, 0)
myfile = open('D:/A/'+i,encoding="utf8").read()
myfile = re.sub(r'^(Dir|\d{2}:|$).*\R',' ', myfile) # remove all non-XML-compatible characters
p = document.add_paragraph(myfile)
document.save('D:/A/'+i+'.docx')
Cám ơn các bạn
Lần chỉnh sửa cuối: