首页 > Python资料 博客日记

Python os.ttyname()方法

2023-08-08 13:53:19Python资料围观309

这篇文章介绍了Python os.ttyname()方法,分享给大家做个参考,收藏Python资料网收获更多编程知识

Python的ttyname()方法返回一个字符串,它指定与fd关联的终端设备。 如果fd与终端设备没有关联,则会出现异常。

语法

以下是ttyname()方法的语法 -

os.ttyname(fd)

参数

  • fd - 这是文件描述符。

返回值

  • 该方法返回一个指定终端设备的字符串,仅在Unix系统上可用。

示例

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

# !/usr/bin/python33
import os, sys

# Showing current directory 
print ("Current working dir :%s" %os.getcwd())

# Changing dir to /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!!

版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!

标签:

相关文章

本站推荐