易截截图软件、单文件、免安装、纯绿色、仅160KB

Python 有权重的随机选择, Weighted Random Choice

import random def windex(lst):
    '''an attempt to make a random.choose() function that makes weighted choices
    accepts a list of tuples with the item and probability as a pair'''
    wtotal = sum([x[1] for x in lst])
    n = random.uniform(0, wtotal)
    for item, weight in lst:
        if n < weight:
            break
        n = n - weight
    return item


相关文档:

保存指定文件夹下的目录和文件名到文件中 Python 脚本

真是倒霉,刚买不久的移动硬盘,昨天删除一个分区失败后,几个分区都不见了,拿去修,未果
换了个新的,但其中数据全没了。那是我平时收集的很有用的资料
很多都可以重新下载,但怎能想起硬盘中的所有东西
今天换硬盘回来
就像写一个保存指定路径下所有文件夹和文件名的程序
这样,如果东西丢了,看看那里有些什么,也 ......

python天天进步(2) 文件操作之遍历目录

 
Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数:
os.listdir(dirname):列出dirname下的目录和文件
os.getcwd():获得当前工作目录
os.curdir:返回当前目录('.')
os.chdir(dirname):改变工作目录到dirname
os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false ......

用python连接mysql数据库


#
-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
#
连接数据库
try
:
conn
=
MySQLdb.connect(host
=
'
localhost
'
,user
=
'
root
'
,passwd
=
'
xxxx
'
,db
=
'
test1
'
)
except
Exception, e:
print
e
sys.exit()
......

[Python module] select

16.1. select — Waiting for I/O completion¶
This module provides access to the select and poll functions available in most operating systems, epoll available on Linux 2.5+ and kqueue available on most BSD. Note that on Windows, it only works for sockets; on other operating systems, it al ......

用python, c#, java写的文件拷贝

     前一段时间试着用这三种语言简单的写了关于文件拷贝的程序,发现c#和python的api惊人的相似,对于文件的操作这两种语言非常的方便。都没有加异常的处理
C#源代码:
        public static void CopyFile(string source, string destination)
  & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号