Python os.ttyname() 方法

Python 教程 · 2019-02-04 13:29:39

概述

os.ttyname() 方法用于返回一个字符串,它表示与文件描述符fd 关联的终端设备。如果fd 没有与终端设备关联,则引发一个异常。

语法

ttyname()方法语法格式如下:

os.ttyname(fd)

参数

  • fd -- 文件描述符

返回值

返回一个字符串,它表示与文件描述符fd 关联的终端设备。

实例

以下实例演示了 ttyname() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

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

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

p = os.ttyname(fd)
print "关联的终端为: "
print p
print "done!!"

os.close(fd)
print "关闭文件成功!!"

执行以上程序输出结果为:

当前目录 :/tmp
关联的终端为:
/dev/tty
done!!
关闭文件成功!!

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

Ethnography and Virtual Worlds

Ethnography and Virtual Worlds

Tom Boellstorff、Bonnie Nardi、Celia Pearce、T. L. Taylor / Princeton University Press / 2012-9-16 / GBP 21.00

"Ethnography and Virtual Worlds" is the only book of its kind - a concise, comprehensive, and practical guide for students, teachers, designers, and scholars interested in using ethnographic methods t......一起来看看 《Ethnography and Virtual Worlds》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具