Skip to content

Instantly share code, notes, and snippets.

@Suave
Created November 19, 2010 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Suave/706311 to your computer and use it in GitHub Desktop.
Save Suave/706311 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