Home » Python

Python File isatty() Method with Example

Python File isatty() Method: Here, we are going to learn about the isatty() method, how to check whether a file is an interactive or not in Python?
Submitted by IncludeHelp, on December 22, 2019

File isatty() Method

isatty() method is an inbuilt method in Python, it is used to check whether a file stream is an interactive or not in Python i.e. a file stream is connected to a terminal device. If a file is connected to a terminal then it will be an interactive and the method will return "True".

Syntax:

    file_object.isatty()

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is <class 'bool'>, it returns True if file stream is an interactive and returns False if files is not interactive.

Example:

# Python File isatty() Method with Example

# creating a file
myfile1 = open("hello1.txt", "w")

# checking whethet the file stream is 
# an interactive
print("myfile1.isatty():", myfile1.isatty())

# closing the file
myfile1.close()

# opening file in read mode
myfile1 = open("hello1.txt", "r")

# checking whethet the file stream is 
# an interactive
print("myfile1.isatty():", myfile1.isatty())

# closing the file
myfile1.close()

Output

myfile1.isatty(): False
myfile1.isatty(): False






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.