fileinput.filename() in Python Last Updated : 22 Apr, 2020 Improve Improve Like Article Like Save Share Report 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 : Like Article Suggest improvement Next fileinput.filelineno() in Python Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Python: Inplace Editing using FileInput fileinput.lineno() in Python fileinput.filelineno() in Python fileinput.isfirstline() in Python fileinput.input() in Python Get filename from path without extension using Python How to create filename containing date or time in Python glob – Filename pattern matching Important differences between Python 2.x and Python 3.x with examples Python program to build flashcard using class in Python Like J Jitender_1998 Follow Article Tags : Python fileinput-library Python Practice Tags : python