Spring的註解形式:@Repository、@Service、@Controller的作用
阿新 • • 發佈:2021-11-24
1.從一個檔案中讀取內容(比如有3列內容),然後再新增加2列欄位,並存放在列表中(一共5列)。
2.開啟一個新的檔案,迴圈包含有5列表欄位的列表,並將內容寫進新的檔案。
import random def writecChannelIdFile(fp, writeFile): channel_ids = {'125002805': "135379412029940069", '125102805': "287200733847731473"} # 125002805:微信 125102805:支付寶 channel_id = ['125002805', '125102805'] with open(fp,"r") as ff: myReadFile = ff.readlines() orderList = [] for line in myReadFile: channel_id_choice = random.choice(channel_id) #隨機取列表的內容(一定要放在for迴圈裡面) newLine = line.replace("\n", ",")+channel_id_choice +"," + channel_ids[channel_id_choice]print(newLine) orderList.append(newLine) with open(writeFile, 'w')as wf: for order in orderList: print(order) wf.write(order+"\n") if __name__ == "__main__": fp = r"D:\xxx\xxx\xxx\a.txt" #讀取該路徑下的a.txt檔案 writeFile = r"D:\xxx\xxx\xxx\b.txt" #會在該路徑下生成一個b.txt的檔案 writecChannelIdFile(fp, writeFile)