The Wayback Machine - https://web.archive.org/web/20220721171139/https://www.geeksforgeeks.org/fileinput-input-in-python/
Skip to content
Related Articles

Related Articles

fileinput.input() in Python

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 22 Apr, 2020

With the help of fileinput.input() method, we can get the file as input and to can be used to update and append the data in the file by using fileinput.input() method.

Syntax : fileinput.input(files)

Return : Return the data of the file.

Example #1 :
In this example we can see that by using fileinput.input() method, we are able to get the data of the file line by line by using this method.

Input File –
Image




# import fileinput
import fileinput
  
# Using fileinput.input() method
for line in fileinput.input(files ='gfg.txt'):
    print(line)

Output :
Image
 
Example #2 :

Input Files –
ImageImage




# import fileinput
import fileinput
  
# Using fileinput.input() method
for line in fileinput.input(files =('gfg.txt', 'gfg1.txt')):
    print(line)

Output :
Image

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!