Saturday, November 16, 2024
Google search engine
HomeLanguagesfileinput.filename() in Python

fileinput.filename() in Python

With the help of fileinput.filename() method, we can get the last used file name which we have used so far by using fileinput.filename() method.

Syntax : fileinput.filename()

Return : Return the last used file name.

Example #1 :
In this example we can see that by using fileinput.filename() method, we are able to get the last used file name by using this method.




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


Output :

Example #2 :




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


Output :

Last Updated :
22 Apr, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments