OS File 中的 os.ttyname(fd)函数

首页 / Python2入门教程 / OS File 中的 os.ttyname(fd)函数

Python方法ttyname()返回一个字符串,该字符串指定与fd关联的终端设备。如果fd不与终端设备关联,则引发异常。

os.ttyname(fd) - 语法

os.ttyname(fd)
  • fd  -  这是文件描述符。

os.ttyname(fd) - 返回值

此方法返回指定终端设备的字符串。

os.ttyname(fd) - 示例

以下示例显示ttyname()方法的用法。

无涯教程网

# !/usr/bin/python

import os, sys

# 显示当前目录
print "Current working dir :%s" %os.getcwd()

# 将目录更改为 /dev/tty
fd=os.open("/dev/tty",os.O_RDONLY)

p=os.ttyname(fd)
print "the terminal device associated is: "
print p
print "done!!"

os.close(fd)
print "Closed the file successfully!!"

当无涯教程运行上面的程序时,它产生以下输出-

Current working dir is :/tmp
the terminal device associated is:
/dev/tty
done!!
Closed the file successfully!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

AI技术内参 -〔洪亮劼〕

移动端自动化测试实战 -〔思寒〕

接口测试入门课 -〔陈磊〕

OAuth 2.0实战课 -〔王新栋〕

WebAssembly入门课 -〔于航〕

程序员的个人财富课 -〔王喆〕

零基础实战机器学习 -〔黄佳〕

高并发系统实战课 -〔徐长龙〕

结构会议力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)