#标准输出 sys.stdout.write() sys.stderr.write() #标准输入 while True : try: line = raw_input().rstrip(); except EOFError: break; pass #读取文件 for line in open(fname, "r"): pass; 等价于 fp = open(fname, "r"): while True: line = fp.readline(); if not line: break; pass; 快速方法:(快2-3倍) fp = open(fname, "r"): while True: lines = file.readlines(10000); #参数可缺省 if not lines: break; for line in lines: pass; #写文件 outfp = open(fname, "w"); outfp.write(text);