Is reverse reading possible?
Jeff Epler
jepler at unpythonic.net
Sun Mar 14 14:46:19 EST 2004
4M files are not that big these days.
def reversed_file(name, encoding):
contents = codecs.open(name, "r", encoding).read()
contents = list(contents)
contents.reverse()
return "".join(contents)
Example:
>>> codecs.open("utf-example.txt", "r", "utf-8").read()
u'60: CJK UNIFIED IDEOGRAPHS (0x4E00 - 0x9FFF) | \u4e25\u5f25\u6f25\n'
>>> reversed_file("utf-example.txt", "utf-8")
u'\n\u6f25\u5f25\u4e25 | )FFF9x0 - 00E4x0( SHPARGOEDI DEIFINU KJC :06'
This assumes that you know the encoding for each file in advance, and
that Python has a codec for it.
Jeff
More information about the Python-list
mailing list