2 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
您實(shí)際上需要將這些函數(shù)稱為我的兄弟
def my_func(stuff):
print(stuff) #or whatever
my_func(1234)
每條評論更新
import os
p=r'path\to\your\files'
filelist=os.listdir(p) #creates list of all files/folders in this dir
#make a loop for each file in the dir
for file in filelist:
f=os.path.join(p,file) #this just joins the file name and path for full file path
your_func(f) #here you can pass the full file name to your functions

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
如前所述,當(dāng)前的問題似乎是您根本不調(diào)用cert_check
函數(shù)。但是,盡管此站點(diǎn)實(shí)際上不用于代碼審查,但我不禁建議對您的代碼進(jìn)行一些改進(jìn)。特別是,所有這些try/except:pass
構(gòu)造都使得檢測代碼中的任何錯(cuò)誤變得異常困難,因?yàn)樗挟惓V粫?huì)被靜默捕獲和吞噬except: pass
。
您應(yīng)該刪除所有這些
try/except:pass
塊,尤其是圍繞整個(gè)功能主體的那個(gè)塊如果某些鍵不存在,則可以使用
dict.get
代替代替[]
,這不會(huì)引發(fā)鍵錯(cuò)誤,而是返回None
(或一些默認(rèn)值),并且所有檢查仍然可以進(jìn)行您可以使用
|=
而不是if
檢查來or
檢查變量的結(jié)果您可以
any
用來檢查某個(gè)列表中的任何元素是否滿足某些條件
我的vt_result_check
函數(shù)版本:
def vt_result_check(vt_result_path):
vt_result = False
for filename in os.listdir(path):
with open(filename, 'r', encoding='utf-16') as vt_result_file:
vt_data = json.load(vt_result_file)
# Look for any positive detected referrer samples
# Look for any positive detected communicating samples
# Look for any positive detected downloaded samples
# Look for any positive detected URLs
sample_types = ('detected_referrer_samples', 'detected_communicating_samples',
'detected_downloaded_samples', 'detected_urls')
vt_result |= any(sample['positives'] > 0 for sample_type in sample_types
for sample in vt_data.get(sample_type, []))
# Look for a Dr. Web category of known infection source
vt_result |= vt_data.get('Dr.Web category') == "known infection source"
# Look for a Forecepoint ThreatSeeker category of elevated exposure
# Look for a Forecepoint ThreatSeeker category of phishing and other frauds
# Look for a Forecepoint ThreatSeeker category of suspicious content
threats = ("elevated exposure", "phishing and other frauds", "suspicious content")
vt_result |= vt_data.get('Forcepoint ThreatSeeker category') in threats
return vt_result
添加回答
舉報(bào)