Skip to content

Commit

Permalink
a more elegant solution
Browse files Browse the repository at this point in the history
  • Loading branch information
JaksaVucicevic committed Feb 21, 2012
1 parent c0fd5e3 commit 6c5520d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ def FileList(path):
return glob.glob(path+"/*.txt")

def CheckForN(line):
if string.find(line,": N") == -1 :
if string.find(line,"Sex: N") == -1 :
return False
else :
return True

def FixFile(fname) :
def FixFile(fname,i) :
F = open(fname)
lines = F.readlines()
F.close()
lines[i] = "Sex: M\n";
F = open(fname,'w')
for line in lines :
if not CheckForN(line) :
F.write(line)
else :
F.write("Sex: M\n")
F.write(line)
F.close()

Flist = FileList('cleandata')
for Fname in Flist :
F = open(Fname)
for line in F :
if CheckForN(line) :
print Fname, line
FixFile(Fname)
lines = F.readlines()
for i in range(len(lines)):
if CheckForN(lines[i]) :
print Fname, lines[i]
FixFile(Fname,i)
break
F.close()

Expand Down

0 comments on commit 6c5520d

Please sign in to comment.