views:

46

answers:

2

I'm going to separate over 1000 virus signatures and the virus names. I have them all in a text file, and would like to do this with python.

Here is the format:

virus=signature

I need to be able to take 'virus' and write it to one file, then take 'signature' and write it to another.


This is what I've tied so far:

h = open("FILEWITHSIGS")
j = h.read()
k = h.split('=')

And that is basically where I got stuck. No matter what I tried, it printed (or writed) both to the same place.

+1  A: 
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()
ghostdog74
What if the signature contained an '='..? Sorry SilentGhost is getting my 1UP.
MattH
Exactly what I needed, thanks! +1 for you!
Zachary Brown
+4  A: 
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)
SilentGhost