Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Write a Python program to read last n lines of a file

def read_lastnlines(fname,n):
	with open('file1.txt') as f:
		for line in (f.readlines() [-n:]):
			print(line)

read_lastnlines('file1.txt',3)
Comment

PREVIOUS NEXT
Code Example
Python :: find table with class beautifulsoup 
Python :: python - give a name to index column 
Python :: fill missing values with 0 pandas 
Python :: python count words in file 
Python :: pytorch tensor add one dimension 
Python :: convert seconds to hours python 
Python :: pandas group by month 
Python :: user agents list 
Python :: python pil image flip 
Python :: python requirments.txt 
Python :: python check file format 
Python :: print type of exception python 
Python :: ignore warning sklearn 
Python :: split a path into all subpaths 
Python :: cos in python in degrees 
Python :: how to plot roc curve in python 
Python :: how to sort a list by the second element in tuple python 
Python :: yield godot 
Python :: How to convert an integer number into words in python? 
Python :: generate a list of random numbers python 
Python :: python get file extension from path 
Python :: python print dict pretty 
Python :: python float till 2 decimal places 
Python :: dataframe select entries that are in a list 
Python :: cors error in flask 
Python :: save images cv2 
Python :: find root directory of jupyter notebook 
Python :: cv display image in full screen 
Python :: pandas return first row 
Python :: python import json into pymongo 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =