Wednesday, July 3, 2024
HomeLanguagesPythonlinecache.getline() in Python

linecache.getline() in Python

With the help of linecache.getline() method, we can get a particular line by providing a line number, one of the usecase for this method is to find the syntax error in the given line number within a big file by using linecache.getline() method.

Syntax : linecache.getline(filename, lineno)
Return : Return the content of given line number.

Input File :

Example #1 :
In this example we can see that by using linecache.getline() method, we are able to get the content of a given line from a big file by using this method.




# import linecache
import linecache as lc
  
# Using linecache.getline() method
gfg = lc.getline('File.txt', 1)
  
print(gfg)


Output :

 
Example #2 :




# import linecache
import linecache as lc
  
# Using linecache.getline() method
gfg = lc.getline('File.txt', 2)
  
print(gfg)


Output :

Last Updated :
22 Apr, 2020
Like Article
Save Article

Similar Reads
Related Tutorials
Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments