源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

在Python程序中操作文件之isatty()方法的使用教程

  • 时间:2021-07-31 08:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:在Python程序中操作文件之isatty()方法的使用教程
 如果文件已连接(与终端设备相关联)到一个tty(状)的设备,isatty()方法返回True,否则返回False。 [b]语法[/b] 以下是isatty()方法的语法:
fileObject.isatty();

[b]参数[/b] [list] [*]    NA[/*] [/list] [b]返回值[/b] 如果该文件被连接(与终端设备相关联)到一个tty(类似终端)设备此方法返回true,否则返回false。 [b]例子[/b] 下面的例子显示了isatty()方法的使用。
#!/usr/bin/python

# 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

  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部