Display the name of the file in file handling in python by R4R Team

-In file handling, we operate many files in the program and make multiple file objects, to get the name from the file object we have a 'name' attribute in the python.

Syntax-

fileobject.name


program-

f1=open('file1','w')
f2=open('file2','w')
f3=open('file3','a')
f4=open('file4','x')
print(f1.name)
print(f2.name)
print(f3.name)
print(f4.name)


output-

file1
file2
file3
file4


-In this program, we open the different files in different modes and make file object for each file, then using fileobject.name we will print the name of the file.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!