摘要: 临时文件definition: import tempfile tempfile_name = tempfile.mktemp() # 创建名称唯一的临时文件供使用 temp1 = tempfile.TemporaryFile() # 注意:用TemporaryFile()创建的文件没有文件名 temp11= tempfile.TemporaryFile(mode='w+t') temp2 = tempfile.NamedTemporaryFile() # 尽管文件带有名字,但它仍然会在close后自动删除 temp... 阅读全文
posted @ 2013-02-07 10:37 道以万计 阅读(284) 评论(0) 推荐(0) 编辑
摘要: stdin: 0, stdout: 1, stderr: 2例2:(注cmd重定向进入后用exit返回原目录) cmd > file 把 stdout 重定向到 file 文件中 cmd >> file 把 stdout 重定向到 file 文件中(追加) cmd 1> file 把 stdout 重定向到 file 文件中 cmd > file 2>&1 把 stdout 和 stderr 一起重定向到 file 文件中 cmd 2> file 把 stderr 重定向到 file 文件中 cmd 2>> file 把 stder 阅读全文
posted @ 2013-02-07 10:30 道以万计 阅读(4046) 评论(0) 推荐(0) 编辑
摘要: summary:import timecur_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))一、小应用1.python获取当前时间time.time() 获取当前时间戳 1180759620.859time.localtime() 当前时间的struct_time形式 (2007, 6, 2, 12, 47, 7, 5, 153, 0)time.ctime() 当前时间的字符串形式 ’Sat Mar 28 22:24:24 2009′ISOTIMEFORMAT=’%Y-%m-%d %X 阅读全文
posted @ 2013-02-07 10:24 道以万计 阅读(162) 评论(0) 推荐(0) 编辑
摘要: '''Created on Jan 28, 2013@author: changxue@summary: to look for a file by filename within specified directory, or look for some word in files'''import osimport sysdef search_file(key, scope): for parent, dirs, files in os.walk(scope): if key in files: print parent, ... 阅读全文
posted @ 2013-02-07 10:16 道以万计 阅读(369) 评论(0) 推荐(0) 编辑
摘要: '''Created on Feb 6, 2013@author: changxue@summary: to delete all files and directories in specified directory. print the name of file or directory if it can't remove.'''import os, sysdef clean(path): # to deal with abnormal situation if not os.path.exists(path): raise Ex 阅读全文
posted @ 2013-02-07 10:10 道以万计 阅读(243) 评论(0) 推荐(0) 编辑