Python教程
Python教程:包含了所有代写案例以及部分答案
-
#!/usr/bin/env python #coding: utf-8 import md5 import os from time import clock as now def getmd5(filename): file_txt = open(filename, ‘rb’).read() m = md5.new(file_txt) return m.hexdigest() def main(): path = u’C:\\aa\bb\cc\dd’ all_md5 = {} all_siz … 继续阅读“Python删除同一个文件夹下的重复文件代码”
:
-
#!/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封装”
:
-
下面是一个基础的python线程控制类 #!/usr/bin/env python """ testthread.py An example of an idiom for controling threads Doug Fort http://www.dougfort.net """ import threading class TestThread(threading.Thread): """ A sa … 继续阅读“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”
:
-
#coding:utf-8 import struct codeDict={}#全局字典key=字符,value=数字 encodeDict={} filename=None listForEveryByte=[] class Node: def __init__(self,right=None,left=None,parent=None,weight=0,charcode=None): self.right=right self.left=left self.parent=parent sel … 继续阅读“Python实现的哈夫曼编码”
:
-
”’ 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”
:
-
import math L1=[‘104′,’32’,’249′,’177′] L2=[‘191′,’538′,’317′,’795’] L3=[‘735′,’346′,’542′,’429’] L4=[‘434′,’277′,’659′,’132’] L5=[‘866′,’569′,’46’,’763′] def Search_data(store_pdb,List_data): f_pdb=open(store_pdb,’r’) lines=f_pdb.readlines() f_pdb.c … 继续阅读“python 用python 写了一个求空间俩点之间的距离的脚本”
:
-
#coding=utf-8 #异常用法 import sys #—————- #sys.exc_info()[2].tb_lineno值不是固定的 try: x=1/0 except Exception as e: print "Exception:[%s][%s]" % (sys.exc_info()[2].tb_lineno, str(e)) finally: print "This is finally " #———- … 继续阅读“python 演示异常”
:
-
原理先获取所有文件,然后统计每个文件中代码的行数,最后将行数相加,思路很简单。“`python import os import os.path import time rootdir = ‘文件路径’ filelists = [] 遍历文件 def getFile(rootdir): global filelists for parent,dirnames,filenames in os.walk(rootdir): for dirname in dirna … 继续阅读“python 利用python 统计源码行数”
:
-
python 3.4.3 cx_Oracle“` python !/usr/bin/env python import time start = time.clock() import cx_Oracle tns = cx_Oracle.makedsn(‘127.0.0.1’, ‘1534’, ‘dsn’) db = cx_Oracle.connect(‘username’, ‘ … 继续阅读“Python连接Oracle”
: