faqts : Computers : Programming : Languages : Python : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 29 people (90%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How to read only the last 200 bytes from very BIG file?

Feb 6th, 2007 18:34
chao chen, Washington Corrêa, Thomas Rothmayer,


Here it goes:
archive = '/test.txt'
length = os.path.getsize(archive)
f = file(archive, 'r')
f.seek(length-200)
print f.read(200)
ok?
Junior
f = open('test.txt','r')
f.seek(-200,2)
last200 = f.read(200)
CChen