发布网友 发布时间:2022-04-23 00:43
共1个回答
热心网友 时间:2022-04-18 15:35
import glob, os, re
path_a = 'e:\\A'
path_b = 'e:\\B'
a_files = glob.glob('%s\\*' % path_a)
b_files = glob.glob('%s\\*' % path_b)
for f in a_files:
file_name = os.path.basename(f)
file_name_in_folder_b = re.subn(ur'\d{8}_\d{2}_\d{2}_\d{2}_', '', file_name)
full_path = '%s\\%s' % (path_b, file_name_in_folder_b)
if full_path in b_files:
file_in_b = open(full_path, 'r')
追问先谢谢大大
我是PY3.2
为啥会在
file_name_in_folder_b = re.subn(ur'\d{8}_\d{2}_\d{2}_\d{2}_', '', file_name)
这一行的re.subn(ur'\d{8}_\d{2}_\d{2}_\d{2}_',最后的引号那里提示invalid syntax啊
缩进没问题啊
追答file_name_in_folder_b = re.subn(r'\d{8}_\d{2}_\d{2}_\d{2}_', '', file_name)
去掉u就可以了,python3没有这个写法了