Image 01 Image 02

0
Posted on 12th 四月 2009 by admin

在后台运行 django:
nohup python manage.py  &

查看后台某个进程:
ps -ef|grep “python”

杀死进程:
kill -9 34353

重启 apache:
apachectl restart

1
Posted on 8th 一月 2009 by admin

找了半天没找着,终于在英文站点上找到,还有感谢群里的石头和球迷

>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0

别外付一个python对时间的一些函数,很好用的

我们先导入必须用到的一个module
>>> import time
设置一个时间的格式,下面会用到
>>>ISOTIMEFORMAT=’%Y-%m-%d %X’
看一下当前的时间,和其他很多语言相似这是从epoch(1970 年 1 月 1 日 00:00:00)开始到当前的秒数。
>>> time.time()
1180759620.859
上面的看不懂,换个格式来看看
>>> time.localtime()
(2007, 6, 2, 12, 47, 7, 5, 153, 0)
localtime返回tuple格式的时间,有一个和它类似的函数叫gmtime(),2个函数的差别是时区,gmtime()返回的是0时区的值,localtime返回的是当前时区的值。
>>> time.strftime( ISOTIMEFORMAT, time.localtime() )
‘2007-06-02 12:54:29′
用上我们的时间格式定义了,使用strftime对时间做一个转换,如果取现在的时间,time.localtime() 可以不用。

>>> time.strftime( ISOTIMEFORMAT, time.localtime( time.time() ) )
‘2007-06-02 12:54:31′
>>> time.strftime( ISOTIMEFORMAT, time.gmtime( time.time() ) )
‘2007-06-02 04:55:02′
上面展示了gmtime和localtime的区别。
查看时区用
>>> time.timezone
-28800
上面的值是一个秒值,是当前时区和0时区相差的描述,-28800=-8*3600,即为东八区。

0
Posted on 8th 一月 2009 by admin

python提供了好多的数据结构,主要是分list,dict,tuple(数组,字典,元组)

1.list(数组)

数组的方法运用,应该有写过程序的都知道啦

包括二维三维,下面我只说几个方法

[...]

0
Posted on 7th 一月 2009 by admin

# coding=utf-8
import SocketServer

class EchoRequestHandler(SocketServer.BaseRequestHandler ):
def setup(self):
print self.client_address, ‘connected!’
self.request.send(‘hi ‘ + str(self.client_address) + ‘\n’)

def handle(self):
data = ‘dummy’
while data:
data = self.request.recv(1024)
print data
self.request.send(data)
if data.strip() == ‘bye’:
return

def finish(self):
print self.client_address, ‘disconnected!’
self.request.send(‘bye ‘ + str(self.client_address) + ‘\n’)

#server host is a tuple (‘host’, port)
server = SocketServer.ThreadingTCPServer((”, 9000), EchoRequestHandler)
server.serve_forever()

0
Posted on 4th 十二月 2008 by admin

先说明,看本文需要有一定的编程基础(学过其它语言)

下面代码打进去的时候缩进都给过滤掉了(大家自己注意啦)

1.环境搭建

这一点很简单

到www.python.org下载一个window包,装上去,就包含开发环境(IDLE)还有一本很有用的文档

2.开始写代码啦

print “hello world”

保存为 .py的文件,用IDLE打开

然后按”f5″

就可以输出来啦

[...]

0
Posted on 1st 十二月 2008 by admin

一个很有代表性的多线程程序

import threading
import time

class MyThread(threading.Thread):
def run(self):
print “%s started!” % self.getName()
time.sleep(1)
print “%s finished!” % self.getName()

if __name__ == ‘__main__’:
for x in range(4):
mythread = MyThread(name = “Thread-%d” % (x + 1))
mythread.start()
time.sleep(.2)

0
Posted on 28th 十一月 2008 by admin

入门教程

http://wiki.woodpecker.org.cn/moin/WeiZhong

很好用的文档

http://www.woodpecker.org.cn/diveintopython/toc/index.html

数组操作

http://blog.csdn.net/hjue/archive/2008/01/24/2063041.aspx

初学教程

http://wiki.woodpecker.org.cn/moin/March_Liu/PyTutorial