我是一个初学者与python。我正在尝试使用具有以下代码的脚本作为其一部分。我有几个关于这段代码的问题。需要帮助理解这个python代码片段与re.compile()
当前工作目录有两个目录cpt.133131313 /和cpt.38282382328 /。我给这两个目录为arg1和arg2。
究竟发生了什么
"cpt." + arg + ".\d+
?什么应该是arg以便
if re.compile("cpt." + arg + ".\d+").search(f)
返回true?allfiles = os.listdir(os.getcwd()) cpts = [] for arg in args: found = False for f in allfiles: if re.compile("cpt." + arg + ".\d+").search(f): found = True cpts.append(f) break if not found: print "missing checkpoint: ", arg
感谢。
从文档开始:http://docs.python.org/2/library/re.html –