Monday, November 18, 2024
Google search engine
HomeLanguageslinecache.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
RELATED ARTICLES

Most Popular

Recent Comments