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!!
上一篇:
Python os模組方法
下一篇:
Python異常處理