2/12/2023 0 Comments Cache text encoding![]() ![]() >linecache.getline('/folder/file.txt', 2) The terminating newline character will be included for lines that are found. ![]() It will return '' on errors or when the line or file in not found. ![]() It returns the nth line from the file that is passed through the file parameter. The first parameter is the file name and the second parameter is the line number that has to be displayed, i.e. Getline() is the most important and commonly used method of linecache module. Linecache module is imported by this- >import linecacheįollowing is a list of linecache module and example of their code- 1. Repeatedly reading the lines and parsing them provides lot of efficiency in time complexity. It returns the requested line(s) by indexing them into a list. This module is used extensively when dealing with Python source files. This is used by the traceback module (which extracts, formats and prints the stack traces of Python programs, it prints the error messages or the exceptions when they are raised int he program) to retrieve source lines and include them in the formatted traceback. Linecache is one of the most useful modules of Python standard library which can be used to have random access to any text file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |