Is reverse reading possible?

Jeff Epler jepler at
Sun Mar 14 20:46:19 CET 2004

4M files are not that big these days.

def reversed_file(name, encoding):
    contents =, "r", encoding).read()
    contents = list(contents)
    return "".join(contents)

>>>"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.


More information about the Python-list mailing list