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

python random 随机的问题

在一个项目中需要获取随机数,谁知道遇到点问题:随机数不随机。所以我写了个简单原型。看下到底是啥问题。
import os,random,sys,time
while True:
father = os.fork()
if father:
time.sleep(2)
rd = 7
else:
#random.seed()
rd = random.choice([2,3,4,5])
print rd
time.sleep(2)
sys.exit(0)

代码基本就这样。谁知道在子进程里面打印的 random  不起作用。每次随机数都是一样的。
测试发现。是 while 出现问题,因为while 一直循环,而随机种子,是在第一次 import random 的时候就已经种下了。所以导致随机数一直都不会变化~~~  汗。幼稚问题导致浪费很多时间
看random.seed手册解释:
If x is omitted or None, current system time is used; current system time is also used to initialize the generator when the module is first imported.
明白了。最后用 random.seed() 来改变随机种子。。


相关文档:

c语言模拟perl python中的数组负数索引

int main()
{
int a[] = {1,2,3,4,5};
int i;
int * p = a;
for (p = a + 4, i = 0; i < 5; i++) {
printf("%d ",p[-i]);
}

return 0;
}

......

使用python 3.0 处理utf8格式的文件BOM问题

最近下载了一份最新的python3.0玩儿
没想到print(Hello world)就难为了我半天
问题1,print函数
后来看了一下更新的文档才知道,3.0以后print已经被封装成函数了
而我还一直习惯2.6的 print 'Hello World'形式, 汗一个!
问题2,notepad的utf8格式
我使用notepad写了个测试文件,保存为utf8格式
格式大概是:
test& ......

Python 游戏初学

import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''

#print ('this is init funnction') ......

python实现twitter client

公司的代理可以直接穿墙,自由访问Twitter、Facebook等网站,这两天研究了一下Twitter提供的API,用python写了一个twitter client,只实现了基本功能,查看自己的twitter消息,也可以不验证,查看public的twitter消息。其他功能实现类似。主要函数如下:
def fetch_with_proxy(proxy, username, password, url):
 &n ......

我的VIM配置(ubuntu+python)

1,不用修改/etc/vim下的vimrc及gvimrc文件 。。。
      2,在~目录下,新建一个.vimrc的配置文件。内容如下:(高亮,自动对齐,自动缩进,显示行号)
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2006 Nov ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号