python中pycurl库的用法实例,pythonpycurl


本文实例讲述了python中pycurl库的用法,分享给大家供大家参考。

该实例代码实现从指定网址读取网页,主要是pycurl库的使用。

具体实现方法如下:

#定义一个类
class CallBack:
  """
      for pycurl  
  """

  def __init__(self):
    """Constructor"""
    self.data = ""
  def func(self, data):
    self.data = self.data + data
  
    
def urls(md5, location="", option={}):
  c = pycurl.Curl()
  f = CallBack()
  
  c.setopt(pycurl.URL, "http://XXXXXX/getUrl.php?key=%s" % md5)
  c.setopt(pycurl.WRITEFUNCTION, f.func)
  
  c.perform()
  c.close()
  return f.data

希望本文所述对大家的Python程序设计有所帮助。


Python中help()的用法

()是你要查询的mod 名字
 

简明python一个实例不解?

用python自己的zip库: zlib 或 zipfile

后一个比较高级,推进。具体用法看这篇博文
blog.chinaunix.net/u1/39578/showart_356627.html

=====================
import zipfile, os

z = zipfile.ZipFile(filename, 'w') # 注意这里的第二个参数是w,这里的filename是压缩包的名字

#假设要把一个叫testdir中的文件全部添加到压缩包里(这里只添加一级子目录中的文件):
if os.path.isdir(testdir):
for d in os.listdir(testdir):
z.write(testdir+os.sep+d)
# close() 是必须调用的!
z.close()
参考资料:blog.chinaunix.net/u1/39578/showart_356627.html
 

评论关闭