Home » Python

Python File name Property with Example

Python File name Property: Here, we are going to learn about the name Property, how to get the filename from file object in Python?
Submitted by IncludeHelp, on December 24, 2019

File name Property

name Property is an inbuilt property of File object (IO object) in Python, it is used to get the name of the file from the file object in Python.

Syntax:

    file_object.name

Parameter(s):

  • None

Return value:

The return type of this method is <class 'str'>, it returns the file name.

Example:

# Python File name Property with Example

# creating a file
file1 = open("myfile.txt", "w")

# printing the file name
print("file name is:", file1.name)

# closing the file
file1.close()

Output

file name is: myfile.txt





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.