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

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

截?cái)辔募姆纸M

截?cái)辔募姆纸M

瀟瀟雨雨 2022-12-06 14:51:17
我有以下代碼:# function to truncate filesdef truncate(path):    file_to_truncate = open(path, "w")    file_to_truncate.truncate()    file_to_truncate.close()# truncate all relevant files so they are empty and new results are not written underneath another set of resultstruncate(r'outputA.csv')truncate(r'\outputB.csv')truncate(r'outputC.csv')truncate(r'outputD.csv')truncate(r'outputE.csv')truncate(r'MoutputA.csv')truncate(r'MoutputB.csv')truncate(r'MoutputC.csv')truncate(r'MoutputD.csv')truncate(r"Full Results.csv")truncate(r'results.csv')是否可以縮短此代碼,即截?cái)嗄夸浿械乃形募?
查看完整描述

1 回答

?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以使用os.listdir獲取特定目錄中的所有文件。然后遍歷文件列表并對(duì)它們調(diào)用你的函數(shù):

for file_name in os.listdir():
    truncate(file_name)


查看完整回答
反對(duì) 回復(fù) 2022-12-06
  • 1 回答
  • 0 關(guān)注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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