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) - 返回值

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

链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-ttyname.html

来源:LearnFk无涯教程网

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!!

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

技术教程推荐

技术与商业案例解读 -〔徐飞〕

赵成的运维体系管理课 -〔赵成〕

持续交付36讲 -〔王潇俊〕

Netty源码剖析与实战 -〔傅健〕

微信小程序全栈开发实战 -〔李艺〕

如何落地业务建模 -〔徐昊〕

全链路压测实战30讲 -〔高楼〕

Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕

Python实战 · 从0到1搭建直播视频平台 -〔Barry〕

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