How do I do this in Python (File Manipulation)?

Posted by ThinkCode on Stack Overflow See other posts from Stack Overflow or by ThinkCode
Published on 2010-05-27T17:19:52Z Indexed on 2010/05/27 17:41 UTC
Read the original article Hit count: 123

Filed under:
|

I have a bunch of HTML files in HTML folder. Those HTML files have unicode characters which I solved by using filter(lambda x: x in string.printable, line). Now how do I write the changes back to the original file? What is the best way of doing it? Each HTML file is of 30 kb in size.

  1 import os, string
  2 
  3 for file in os.listdir("HTML/"):
  4     print file
  5     myfile = open('HTML/' + file)
  6     fileList = myfile.readlines()
  9     for line in fileList:
 10         #print line
 11         line = filter(lambda x: x in string.printable, line)
 12     myfile.close()

© Stack Overflow or respective owner

Related posts about python

Related posts about file-io