- 2026年07月08日
- 星期三
本节内容 1.算法定义 算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机制。也就是说,能够对一定规范的输入,在有限时间内
日志格式如下:[ 2016-06-28T00:10:33-03:00 ] xxx.xx.xx.xxx /api/index/xxx/ERR: code:400message:params:country:ustoken:uq6euz9dou6aqtk1Python(3)脚本如下:import urllib.requestimport ntpathimport os, sysimport timedef dirList(path):filelist
python 字典(dict)的特点就是无序的,按照键(key)来提取相应值(value),如果我们需要字典按值排序的话,那可以用下面的方法来进行:1 下面的是按照value的值从大到小的顺序来排序。dic = {a:31, bc:5, c:3, asd:4, aa:74, d:0}dict= sorted(dic.items()
一、Python Base64编码Python中进行Base64编码和解码要用base64模块,代码示例:#-*- coding: utf-8 -*-import base64str = cnblogsstr64 = base64.b64encode(str)print str64 #Y25ibG9ncw==print base64.b64decode(str64) #cnblogs二、MD5#Python 2.ximport
读取JSON文件可以用JSON库,示例代码:#coding:utf-8import jsonwith open(msg.json) as jsonfile:json_data = json.load(jsonfile)for key in json_data:val = json_data[key]print key + t + val
#-*- coding: utf-8 -*-import datetime#给定日期向后N天的日期def dateadd_day(days):d1 = datetime.datetime.now()d3 = d1 + datetime.timedelta(days)return d3#昨天def getYesterday():today = datetime.date.today()oneday = datetime.timedelta(days=1)
一、语法#!/usr/bin/pythonfilename=hello#try except finally demotry:open(abc.txt)print helloexcept IOError,msg:print the file not existexcept NameError,msg:print hello not definedfinally:print end#throw exceptionif filename == hello:raise Ty
一、安装MySQL-python# yum install -y MySQL-python二、打开数据库连接#!/usr/bin/pythonimport MySQLdbconn = MySQLdb.connect(user=root,passwd=admin,host=127.0.0.1)conn.select_db(test)cur = conn.cursor()三、操作数据库def insertdb():sql = insert
demo#!/usr/bin/pythonclass Person:name = jimage = 25def say(self):print My name is + self.name + , and age is + str(self.age)p = Person()p.say()print p.name
