第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Python腳本未產(chǎn)生任何輸出

Python腳本未產(chǎn)生任何輸出

qq_笑_17 2021-05-03 17:12:13
我有一個(gè)python腳本,試圖在其中讀取目錄中的所有.txt文件,并確定它們是否針對腳本中的任何條件返回True或False。我沒有收到錯(cuò)誤消息,但腳本未產(chǎn)生任何輸出。我希望腳本讀取包含以.json格式格式化的文本的.txt文件。然后,我希望腳本確定.txt文件是否與下面我的代碼中的任何語句匹配。然后,我想將結(jié)果輸出到一個(gè)csv文件。非常感激你的幫助!#!/usr/bin/env python# regarding whether any positive results were found for the domain on VT.import csvimport jsonimport pprintimport sysimport osCSVPATH = 'CsvResults.csv'VTOUTPUTPATH = './output/'VTOUTPUTEXT = '.txt'#files_to_search = [f for f in os.listdir('./output/') if f[-4:] == '.txt']#vt_result_path = files_to_search#vt_result = vt_result_check(vt_result_path)pp = pprint.PrettyPrinter(indent=4)# Check files from VirusTotal queries for any positive results# Result is false unless any nonzero positive result is truedef vt_result_check(vt_result_path):    vt_result = None    try:        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)            #vt_result_path = [f for f in os.listdir('./output/') if f[-4:] == '.txt']            #vt_result = None            #try:            #    vt_result = False            #    with open(infile) as vt_result_file:            #        vt_data = json.load(vt_result_file)            # Look for any positive detected referrer samples            try:                for sample in (vt_data['detected_referrer_samples']):                    if (sample['positives'] > 0):                        vt_result = True            except:                pass            # Look for any positive detected communicating samples            try:                for sample in (vt_data['detected_communicating_samples']):                    if (sample['positives'] > 0):                        vt_result = True            except:                pass       
查看完整描述

2 回答

?
jeck貓

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


查看完整回答
反對 回復(fù) 2021-05-11
?
慕村225694

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


查看完整回答
反對 回復(fù) 2021-05-11
  • 2 回答
  • 0 關(guān)注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號