Python自动关闭,当一个文件的引用对象被重新分配给另外一个文件。它使用close()方法来关闭一个文件一个很好的做法。
语法
以下是close()方法的语法:
fileObject.close();
参数
NA返回值
此方法不返回任何值
例子
下面的例子显示了close()方法的使用
#!/usr/bin/python # Open a file fo = open("foo.txt", "wb") print "Name of the file: ", fo.name # Close opend file fo.close()
当我们运行上面的程序,它会产生以下结果:
Name of the file: foo.txt
查看更多关于Python编程中用close()方法关闭文件的教程的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did88853