Skip to content

Instantly share code, notes, and snippets.

View nooperpudd's full-sized avatar

Winton nooperpudd

  • China
View GitHub Profile
@nooperpudd
nooperpudd / urllib.py
Last active August 24, 2017 05:42
urllib2 get the web content .
import urllib2, zlib
def GetContent(url, gzip=False, charset=None, headers=None):
"用于解析url内容"
try:
msg = None
if headers:
request = urllib2.Request(url=url, headers=headers)
else:
@nooperpudd
nooperpudd / with 上下文管理
Created October 6, 2013 12:24
with context api examples
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class WithInContext(object):
"""docstring for WithInContext"""
def __init__(self,context):
print "WithInContext.__init__(%s)" % context
def do_something(self):
print "WithInContext.do_something"
@nooperpudd
nooperpudd / iterstools
Created October 6, 2013 11:58
python itertools examples
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from itertools import *
# imap
for i in imap(lambda x:x*2,xrange(5)):
print i
# starmap
values=[(1,2),(5,23),(8,9)]