Python 当windows无法创建已存在的文件时,正则表达式列表文件
基本上,我只想列出那些windows不会创建的文件。 我如何列出4.txt和4a.txt来代替Python 当windows无法创建已存在的文件时,正则表达式列表文件,python,regex,Python,Regex,基本上,我只想列出那些windows不会创建的文件。 我如何列出4.txt和4a.txt来代替s==s是否为真 myList = ''' 4.txt 4a.txt spam ''' myregex = 'a' s = re.sub(myregex,'',myList) if s == s: print "got it!" # prints 'got it' print s == s # prints 'true' 代码: 输出: =============
s==s
是否为真
myList = '''
4.txt
4a.txt
spam
'''
myregex = 'a'
s = re.sub(myregex,'',myList)
if s == s:
print "got it!" # prints 'got it'
print s == s # prints 'true'
代码:
输出:
=================================================重新启动================================
4.txt matches 4\w?\.txt
4.txt matches 4.*\.txt
4.txt matches \d\w?\.txt
4a.txt matches 4\w?\.txt
4a.txt matches 4.*\.txt
4a.txt matches \d\w?\.txt
spam does not match 4\w?\.txt
spam does not match 4.*\.txt
spam does not match \d\w?\.txt
您不需要正则表达式来完成此操作。
只需使用
os.path.exists
import os
lst = [your_fileNames....]
for arch in lst:
if not os.path.exists(arch):
print arch
你应该把这篇文章贴上python的标签。我不明白你的问题。你似乎误解了很多事情。为什么把
s==s
放在那里,它的计算结果总是True
?
import os
lst = [your_fileNames....]
for arch in lst:
if not os.path.exists(arch):
print arch