Python教程

Python教程:包含了所有代写案例以及部分答案

  • #!/usr/bin/env python #coding:utf-8 import urllib2 import re import os def getHtml(url): #获取html源码 headers={"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"} req=urllib2.Request(url,headers=headers) response=urllib … 继续阅读“python 翻页抓取”

    :
  • # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * from modules.UrlGet import UrlGet from modules.SameSite import SameSite import resource.resources class Main_Window(QMainWindow): def __init_ … 继续阅读“python web小工具”

    :
  • #!/usr/bin/env python #-*- coding:utf-8-*- from mysql import connector def connect(): config={ ‘host’:’localhost’,#默认127.0.0.1 ‘user’:’root’, ‘password’:’1111111′, ‘port’:3306 ,#默认即为3306 ‘database’:’test’, ‘charset’:’utf8’#默认即为utf8 } try: return conn … 继续阅读“python Mysql connector封装”

    :
  • def iquery(conn, sql, rowfactory=tuple, batch=1, *args, **kwgs): """在给定的数据库连接conn上执行sql(可带有参数*args或命名参数**kwgs) rowfactory指定输出物为元组/字典(或字典的扩展类) /或使用用命名参数的函数的结果 batch <= 0时, 直接全部输出 batch == 1时, 逐记录输出 batch >= 1时, 按指定的数量形成批次列表 " … 继续阅读“python common iter query”

    :
  • ”’ print the "Hello, world!" on the console ”’ import os ”’ read data in file ”’ class File: def __init__(self): self.data = os.getcwd()+’\\data.txt’ self.datalines = self.readDataToList() def readDataToList(self): data = [] try: file = … 继续阅读“python初学之helloworld”

    :