os.ttyname(fd)
fd -- 這是在檔案描述符
# !/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!!