mercredi 25 juin 2014

Python code for replacing texts not working


Vote count:

0




My code is this.



import fileinput
for line in fileinput.FileInput("aaaa.txt",inplace=1):
map_dict = {'\N':'999999999', '[':'(', '&':'&'}
line = ''.join(map_dict.get(c,c) for c in line)
print line,


I experimented this with aaaa.txt but it's simply not replacing anything.


A simpler code that I know works is



import fileinput
for line in fileinput.FileInput("label(Nreplaced).txt",inplace=1):
line = line.replace("\N","999999999")
print line,


But I want to make the first code work, because it replaces multiple things.



asked 44 secs ago






Aucun commentaire:

Enregistrer un commentaire