Python的ttyname()
方法返回一個字串,它指定與fd
關聯的終端裝置。 如果fd
與終端裝置沒有關聯,則會出現異常。
語法
以下是ttyname()
方法的語法 -
os.ttyname(fd)
引數
返回值
範例
以下範例顯示了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!!