Python os.isatty () method
Python OS file / directory methods
Outline
os.isatty () method is used to determine if the file descriptor fd is open, and is connected tty (-like) device, it returns true, otherwise False.
grammar
isatty () method syntax is as follows:
os.isatty()
parameter
- no
return value
If the file descriptor fd is open, and connected with the tty (-like) device, it returns true, otherwise False.
Examples
The following example demonstrates isatty () method of use:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 os.write(fd, "This is test") # 使用 isatty() 查看文件 ret = os.isatty(fd) print "返回值: ", ret # 关闭文件 os.close( fd )
The above program output is:
返回值: False