Python3 file.isatty()方法

如果檔連接(與終端設備相關聯)至tty(類似的)設備,isatty()方法返回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

上一篇: Python3模組 下一篇: Python3檔方法