开发手册 欢迎您!
软件开发者资料库

Python 文件(File) isatty() 方法

和其它编程语言一样,Python 也具有操作文件(I/O)的能力,比如打开文件、读取和追加数据、插入和删除数据、关闭文件、删除文件等。本文主要介绍Python 文件(File) isatty() 方法。

Python 文件方法

例如:

判断文件是否已连接到终端设备:

f = open("demofile.txt", "r")print(f.isatty())

1、定义和用法

如果文件流是交互式的,则isatty()方法返回True例如:连接到终端设备。

2、调用语法

file.isatty()

3、参数说明

没有参数

4、使用示例

#!/usr/bin/python# -*- coding: UTF-8 -*-# 打开文件fo = open("demofile.txt", "wb")print "文件名为: ", fo.nameret = fo.isatty()print "返回值 : ", ret# 关闭文件fo.close()

Python 文件方法