Python os.isatty() 方法

Python 教程 · 2019-02-03 22:29:16

概述

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 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

Beginning ARKit for iPhone and iPad

Beginning ARKit for iPhone and iPad

Wallace Wang / Apress / 2018-11-5 / USD 39.99

Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具