Python教程
Python教程:包含了所有代写案例以及部分答案
-
#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”
:
-
#!/usr/bin/python """ 2015.07.02 Clean all the genrated files during compile. Edited by Grey """ import os,re def CleanAll(file_ext): # remove all files in bin for root,dirs,files in os.walk(‘./bin’): for each_file in fi … 继续阅读“python 删除指定格式的文件”
:
-
#!/usr/bin/env python import socket import sys import threading import time NORMAL = 0 ERROR = 1 TIMEOUT = 5 def ping(ip , port , timeout=TIMEOUT): try: cs=socket.socket(socket.AF_INET,socket.SOCK_STREAM) cs.settimeout(float(timeout)) address=(str(ip … 继续阅读“python编写的一个通过多线程扫描端口的代码”
:
-
class JianKong(): ”’查询IDC信息,封ip和过白名单”’ def __init__(self): pass @classmethod def ip_verify(cls,str): ‘验证IP地址规范’ pattern=re.compile(‘(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1 … 继续阅读“python 匹配IP和匹配域名”
:
-
文件型数据库sqllite读写操作:“`python None MySQL数据库读写操作:“`python def ExecSql(sql, dbName="", host="", user="", passwd="", charset=”): import MySQLdb conn = MySQLdb.connect(host=host, user=user, passwd=passwd, char … 继续阅读“Python数据库操作”
: