fileinput.lineno() in Python Last Updated : 22 Apr, 2020 Comments Improve Suggest changes Like Article Like Report With the help of fileinput.lineno() method, we can get the line number for every line on line read from input file by using fileinput.lineno() method. Syntax : fileinput.lineno() Return : Return the line number. Example #1 : In this example we can see that by using fileinput.lineno() method, we are able to get the line number for every line read from the given file by using this method. Input File - Python3 1=1 # import fileinput import fileinput # Using fileinput.lineno() method for line in fileinput.input(files ='gfg.txt'): print('{}. '.format(fileinput.lineno()) + line) Output : Example #2 : Input File - Python3 1=1 # import fileinput import fileinput # Using fileinput.lineno() method for line in fileinput.input(files =('gfg.txt', 'gfg1.txt')): print('{}. '.format(fileinput.lineno()) + line) Output : Comment More infoAdvertise with us Next Article fileinput.lineno() in Python J Jitender_1998 Follow Improve Article Tags : Python Python fileinput-library Practice Tags : python Similar Reads fileinput.input() in Python With the help of fileinput.input() method, we can get the file as input and can be used to update and append the data in the file by using fileinput.input() method. Python fileinput.input() Syntax Syntax : fileinput.input(files) Parameter : fileinput module in Python has input() for reading from mul 2 min read fileinput.filelineno() in Python With the help of fileinput.filelineno() method, we can get the line number for every line on line read for every file from input file by using fileinput.filelineno() method. Syntax : fileinput.filelineno() Return : Return the line number for every file. Example #1 : In this example we can see that b 1 min read fileinput.isfirstline() in Python With the help of fileinput.isfirstline() method, we can get the boolean value as True if line read from the file is very first line else false by using fileinput.isfirstline() method. Syntax : fileinput.isfirstline() Return : Return True if line read is first line of that file. Example #1 : In this 1 min read Open a File in Python Python provides built-in functions for creating, writing, and reading files. Two types of files can be handled in Python, normal text files and binary files (written in binary language, 0s, and 1s). Text files: In this type of file, each line of text is terminated with a special character called EOL 6 min read File Mode in Python In Python, the file mode specifies the purpose and the operations that can be performed on a file when it is opened. When you open a file using the open() function, you can specify the file mode as the second argument. Different File Mode in PythonBelow are the different types of file modes in Pytho 5 min read Read a file line by line in Python Python provides built-in functions for creating, writing, and reading files. Two types of files can be handled in Python, normal text files and binary files (written in binary language, 0s, and 1s). In this article, we are going to study reading line by line from a file.Example:Pythonwith open('file 4 min read Importing Multiple Files in Python Here, we have a task to import multiple files from a folder in Python and print the result. In this article, we will see how to import multiple files from a folder in Python using different methods. Import Multiple Files From a Folder in PythonBelow, are the methods of importing multiple files from 2 min read File Handling in Python File handling refers to the process of performing operations on a file such as creating, opening, reading, writing and closing it, through a programming interface. It involves managing the data flow between the program and the file system on the storage device, ensuring that data is handled safely a 7 min read 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 : R 1 min read File flush() method in Python The flush() method in Python is used to quickly send data from the computer's temporary storage, known as a buffer, to a file or the screen. Normally, when you write something in Python, it doesn't get saved or shown right away. It stays in a buffer for a short time to make things faster. But someti 3 min read Like