Python教程

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

  • 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”

    :
  • #!/usr/bin/env python # -*- coding:utf-8 -*- from gevent import monkey monkey.patch_all() from gevent.pool import Pool import requests import sys import os def download(url): chrome = ‘Mozilla/5.0 (X11; Linux i86_64) AppleWebKit/537.36 ‘ + \ ‘(KHTML, … 继续阅读“python 批量下载文件”

    :
  • #水仙花数 #narcissistic number #水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。 #(例如:1^3 + 5^3+ 3^3 = 153) import math import string for x in range(1,10): a=x*x*x for y in range(0,10): b=y*y*y for z in range(0,10): c=z*z*z d=a+b+c w=’%d’ %x+’%d’ %y+’%d’ %z … 继续阅读“python 水仙花数”

    :