Python方法ttyname()返回一个字符串,该字符串指定与fd关联的终端设备。如果fd不与终端设备关联,则引发异常。
os.ttyname(fd)
fd - 这是文件描述符。
此方法返回指定终端设备的字符串。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-ttyname.html
来源:LearnFk无涯教程网
以下示例显示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!!
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕
Python实战 · 从0到1搭建直播视频平台 -〔Barry〕