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!!
						上一篇:
								Python3文件方法
												下一篇:
								Python3 os文件目录的方法
												
						
						
					
					
					