This article mainly introduces the use of the Isatty () method of manipulating files in a Python program, which is the basic knowledge of Python's introductory study, and needs friends to refer to the following
The Isatty () method returns True if the file is connected (associated with the terminal unit) to a TTY (device), or false.
Grammar
The following is the syntax for the Isatty () method:
?
Parameters
NA
return value
If the file is connected (associated with the terminal unit) to a TTY (similar terminal) device This method returns TRUE, otherwise it returns false.
Example
The following example shows the use of the Isatty () method.
?
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/python # Open a file fo = open ("Foo.txt", "WB") print "Name of the file:", fo.name ret = Fo.isatty () print ' Return value: ', ret # close Opend file Fo.close () |
When we run the above program, it produces the following results:
?
1 2 |
Name of the File:foo.txt return Value:false |
You may be interested in articles: