Python 多CPU编程

       因为工作需要,从Python 2.5开始学习Python,当然只是简单的使用Python完成一些工作,没有很少深入学习。一次,在一个多CPU的环境中,想用Python的多线程编程来达到使用完系统的CPU的目的,结果是不行的。最后发现,Python 2.6以后提供了一个multiprocessing的库,可以达到这个目的。

分享如下:

##多线程编程

[……]

阅读全文

Python对三个数字排序的问题

以下程序为三个数字的排序,并计算所用时间。

#!/usr/bin/env python

def test1(x1=8,x2=5,x3=10,order=None):
    ”’ default is ascending order ”’
    temp1=x1
    temp2=x2
    temp3=x3

    if temp1 > temp2:
        temp1, temp2 = temp2, temp1
    if temp2 > temp3:
        temp2, temp3 = temp3, temp2
    if temp1 > temp2:
        temp1, temp2 = temp2, temp1

    if order is None:
        return [temp1, temp2, temp3]
    else:
        return [temp3, temp2, temp1]
[……]

阅读全文

python 自动安装软件脚本(草稿版)

引用了pamie中的函数。

功能实现:自动安装指定的软件。目前这个只是概念阶段,能够实现的就是自动点击D:\Share\cut\wxPython\LoginAnySetup0942cn.exe 这个软件的第一个下一步(如果是中文操作系统,需要修改‘&Next >’为正确的值)。

## start ——————————-autoinstall.py———————————-

# -*- coding: utf-8 -*- #

[……]

阅读全文

Python的md5 校验

import md5
fname = r”C:\windows\TASKMAN.EXE”
received = md5.md5(file(fname, “rb”).read()).hexdigest()
print received

received 即为16进制的md5校验值。filename是文件的全路径。 

对字符串进行校验

import md5

str = ‘123456789’
received = md5.md5(str).hexdigest()
print received[……]

阅读全文