因此,我编写的代码接受一个pathname
,一个signature
,第三个参数是number
,它表示应该扫描的子目录的深度。在
假设我有一个文件:test:
In it is test1 folder,test2 folder,antivirus.py,simple.py
In test1 folder is antivirus1.py
In test2 folder is test3 folder, and antivirus2.py
In test3 folder is antivirus3.py
所以它应该这样工作:
^{pr2}$这是我当前的代码:
def scan(pathname, signatures, depth):
for item in os.listdir(pathname) and depth > 0:
n = os.path.join(pathname, item)
try:
scan(n, signatures, depth-1)
except:
f = open(n, 'r')
s = f.read()
for virus in signatures:
if s.find(signatures[virus]) > 0:
print('{}, found virus {}'.format(n,virus))
f.close()
for
循环并不是这样工作的。它们的语法是for <variable> in <iterable>
。在只需使用
if
语句:相关问题 更多 >
编程相关推荐