Python Check for unicode files -
i'm new python , have mix of both ansi , unicode (utf-16-le) text based files in series of directories. i've got code reads text files okay until hits unicode file @ mo, i've written in code skip. . i'm wondering if there's anyway can python run
with codecs.open type of thing when hits unicode file part of 1 prog? currrent level of python experience, way see of doing write 2 separate progs; 1 process ansi stuff , 1 unicode.
thanks in advance can provide
use unicode default(which programming discipline) , switch ansi if necessary.
import codecs def opener(filename): try: f = codecs.open(filename, encoding='utf-8') except unicodeerror: f = open(filename) return f
Comments
Post a Comment