Python檔isatty()
方法如果檔連接(與終端設備關聯)到tty(類似)設備則返回True
,否則為false
。
語法
以下是isatty()
方法的語法 -
fileObject.isatty()
參數
- NA
返回值
- 如果檔連接(與終端設備相關聯)到tty(類似)設備,則此方法返回
true
,否則返回false
。
示例
以下示例顯示了isatty()
方法的用法。
#!/usr/bin/python3
# Open a file
fo = open("foo.txt", "wb")
print ("Name of the file: ", fo.name)
ret = fo.isatty()
print ("Return value : ", ret)
# Close opend file
fo.close()
執行上面代碼後,將得到以下結果 -
Name of the file: foo.txt
Return value : False
上一篇:
Python檔對象方法
下一篇:
Python os模組方法