Latest web development tutorials

Python os.isatty() 方法

Python File(文件) 方法 Python OS文件/目錄方法


概述

os.isatty() 方法用於判斷如果文件描述符fd是打開的,同時與tty(-like)設備相連,則返回true, 否則False。

語法

isatty()方法語法格式如下:

os.isatty()

參數

返回值

如果文件描述符fd是打開的,同時與tty(-like)設備相連,則返回true, 否則False。

實例

以下實例演示了isatty() 方法的使用:

#!/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 )

執行以上程序輸出結果為:

返回值:  False

Python File(文件) 方法 Python OS文件/目錄方法