Category Archives: Python 代码

Python 代码

两个算分数(比例)的小程序 [Python]

随手写的小程序 很小很实用, 尤其是在压片的时候计算sar值等方面.
第一个: 化简分数
样例输入1: 16/12
样例输出1: 4 : 3
样例输入2: 16*480/(9*704)
样例输出2: 40 : 33
恩, 简单说来, 就是化任意分数为最简分数
第二个: 小数化分数
给一个范围,用范围[......]

继续阅读

Posted in Python 代码 | Tagged , | Leave a comment  

python统计MYSQL常用的一些性能参数指标

#!/usr/bin/env python
# -*- encoding: utf8 -*-
# Author: iamacnhero@gmail.cn
# Created: 2009-12-14

from __future__ import division
import MySQLdb, ra[......]

继续阅读

Posted in Mysql, Python 代码, Python 数据库 | Tagged , | Leave a comment  

如何把两个列表list(python)中的公共元素去掉?

现有二个list
a = [1, 2, 3]
b = [2, 3, 4]

c = a
a = list(set(a) – set(b))
b = list(set(b) – set(c))

这里主要使用了set的一些操作。

Posted in Python 代码, python 基础 | Tagged | Leave a comment  

找出list中重复最多的N个元素(Python v2.6)

有list[1, 2, 2, 3, 3, 3, 4, 4, 4], 找出重复最多的N个元素。
当然可以遍历list,记下每个item的出现次数然后再来做比较取得。而在这里,我应用了list的一些方法和dict来实现这题目。性能上就不知道哪个好了。
呵呵。。。性能的问题以后再研究,解法如下:
obj[......]

继续阅读

Posted in Python 代码, python 基础 | Tagged | Leave a comment  

python 下载网页

import httplib
conn=httplib.HTTPConnection(“www.baidu.com”)
conn.request(“GET”,”/index.html”)
r1=conn.getresponse([......]

继续阅读

Posted in Python 代码, python 基础, python 模块 | Tagged | Leave a comment  

Python日期计算

1、将字符串转换成date

nowDate = time.strptime(’2010-05-27′, "%Y-%m-%d")

2、获取年、月、日

year = nowDate[0]
month  = nowDate[1]
day  = nowDate[2]

3、日期[......]

继续阅读

Posted in Python 代码, python 基础 | Tagged | Leave a comment  

python发送邮件

# -*- coding:UTF-8 -*-
”’
Created on 2010-5-27

@author: 忧里修斯
”’
import smtplib
import email
from email.message import Message
from email.mime.multi[......]

继续阅读

Posted in Python 代码 | Tagged | Leave a comment  

Python实现ping命令

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""ping.py

ping.py uses the ICMP protocol’s mandatory ECHO_REQUEST
datagram to el[......]

继续阅读

Posted in Python 代码 | Tagged | Leave a comment  

Python截屏程序

说明:必须安装PIL库

# -*- coding:UTF-8 -*-
”’
Created on 2010-5-6

@author: shiyong
”’
import os
from PIL import ImageGrab
import time

class Capturer(obje[......]

继续阅读

Posted in Python 代码 | Tagged , | Leave a comment  

Python HTTP文件上传

# -*- coding:UTF-8 -*-
”’
Created on 2010-4-26

@author: shiyong
”’
import urllib
import sys
import urllib2
import mimetools, mimetypes
import os, s[......]

继续阅读

Posted in Python 代码, python 基础, python 模块 | Tagged | Leave a comment