1 つの基本的な質問 (以下の #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