2012年11月4日
摘要: exists。这个命令将文件名字符串作为参数,如果文件存在的话,它将返回 True,否则将返回 False 1 from sys import argv 2 from os.path import exists 3 4 script, from_file, to_file = argv 5 6 print "Copying from %s to %s" % (from_file, to_file) 7 8 # we could do these two on one line too, how? 9 in_file = open(from_file)10 indata = 阅读全文
posted @ 2012-11-04 10:56 Linuxroot 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 如果你做了上一个练习的加分习题,你应该已经了解了各种文件相关的命令(方法/函数)。你应该记住的命令如下:close – 关闭文件。跟你编辑器的 文件->保存.. 一个意思。 read – 读取文件内容。你可以把结果赋给一个变量。 readline – 读取文本文件中的一行。 truncate – 清空文件,请小心使用该命令。 write(stuff) – 将stuff写入文件。 16.py 1 from sys import argv 2 3 script, filename = argv 4 5 print "We're going to erase %r." 阅读全文
posted @ 2012-11-04 10:36 Linuxroot 阅读(417) 评论(0) 推荐(0) 编辑