[英]Read to right of specific symbol in file from Python
我將分離1000多個病毒簽名和病毒名稱。 我將它們全部保存在一個文本文件中,並希望使用python做到這一點。
格式如下:
virus=signature
我需要能夠使用“病毒”並將其寫入一個文件,然后使用“簽名”並將其寫入另一個文件。
到目前為止,這是我綁定的內容 :
h = open("FILEWITHSIGS")
j = h.read()
k = h.split('=')
基本上這就是我遇到的問題。 不管我嘗試了什么,它都將兩者打印(或寫入)到同一位置。
with open(fname) as inputf, open(virf, 'w') as viruses, open(sigs, 'w') as signatures:
for line in inputf:
virus, _, sig = line.partition('=')
viruses.write(virus + '\n')
signatures.write(sig)
f1=open("first.txt","a")
f2=open("second.txt","a")
for line in open("file"):
s=line.split("=",1)
f1.write(s[0]+"\n")
f2.write(s[-1])
f1.close()
f2.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.