- 2026年07月23日
- 星期四
一、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
简介扩展并增强 datetime 模块的功能。支持 Python 2.3+。官方文档 :http://labix.org/python-dateutil安装两种方法:easy_install :easy_install python-dateutilpip在线安装 :pip install python-dateutil方法1,parse字符串可以很随意,可以用时间日期的英
本节内容 为什么要用版本控制? 假设你在的公司要上线一个新功能,你们开发团队为实现这个新功能,写了大约5000行代码,上线没2天,就发现这个功能用户并不喜欢,你老板让你去掉这个功能,你怎么办?你说简单
