Skip to content

Instantly share code, notes, and snippets.

@rainly
Forked from Suave/python-tips
Created March 17, 2011 10:20
Show Gist options
  • Save rainly/874111 to your computer and use it in GitHub Desktop.
Save rainly/874111 to your computer and use it in GitHub Desktop.
从一个文件里面按行读
f = open(filename, 'r')
while 1:
line = f.readline()
if not line:
break
.....
读 pickle 文件
import cPickle as pickle
f = open(filename, 'r')
data = pickle.load(f)
将标准输出指向文件
def output():
origin = sys.stdout
f = open('no_works.txt', 'w')
sys.stdout = f
main()
sys.stdout = origin
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment