How to read a text file in reverse using python 2.2 -


this question has answer here:

is there way read text file in reverse python 2.2? =)

try following.

# method not using `reverse` function def read_file_reversed(filename):     return open(filename, 'r').readlines()[::-1] 

it reverses list using slicing.
mindful these load entire file memory.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -