def detect_convert(filename):
detector = UniversalDetector()
detector.reset()
cache = b''
with open(filename, 'rb') as f:
for line in f:
detector.feed(line)
cache += line
if detector.done:
break
detector.close()
cache = cache.decode(
detector.result['encoding'] or args.fallback_enc,
errors='ignore')
cache += f.read().decode(
detector.result['encoding'] or args.fallback_enc,
errors='ignore')
cf = convertfunc(cache, args.locale, args.locale_only)
return cf(cache)
评论列表
文章目录