我有一个基本问题(下面的#1)和一个我不知道答案的问题(#2)。任何人都可以提供输入吗?
1.如何将搜索限制为仅特定的,extensions
让我们说只有.c
,,,.h
.cpp
2.如何使下面的in变量"."
之前的点成为可选的"\n"
usertring
userstring="Copyright (c) 2012 Company, Inc.\nAll Rights Reserved.\nCompany Confidential and Proprietary." variable
import os
import sys
import fnmatch
userstring="Copyright (c) 2012 Company, Inc.\nAll Rights Reserved.\nCompany Confidential and Proprietary."
print len(sys.argv)
print sys.argv[1]
if len(sys.argv) < 2:
sys.exit('Usage: python.py <build directory>')
for r,d,f in os.walk(sys.argv[1]):
for files in f:
userlines = userstring.split('\n') # Separate the string into lines
if files.endswith("." + c) or files.endswith("." + cpp):
with open(os.path.join(r, files), "r") as file:
match = 0
for line in file:
if userlines[match] in line.strip('\n\r .'): # Check if the line at index `m` is in the user lines
match += 1 # Next time check the following line
elif match > 0: # If there was no match, reset the counter
match = 0
if match >= len(userlines): # If 3 consecutive lines match, then you found a match
break
if match != len(userlines): # You found a match
print files
编译错误:-
File "test.py", line 12, in <module>
if files.endswith("." + c) or files.endswith("." + cpp):
NameError: name 'c' is not defined