易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Python

[转] 使用Python写Linux的守护进程(daemon)

A simple unix/linux daemon in Python
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
by Sander Marechal
I've
written a simple Python class for creating daemons on unix/linux
systems. It was pieced together for various other examples, mostly
corrections to various Python Cookbook
articles and a couple of examples posted to the Python mailing lists.
It has support for a pidfile to keep track of the process. I hope it's
useful to someone.
Below is the Daemon class. To use it, simply subclass it and implement the run() method.
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.

Usage: subclass the Daemon class and override the run() method
"""
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile

def daemonize(self):
"&q ......

[转] 使用Python写Linux的守护进程(daemon)

A simple unix/linux daemon in Python
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
by Sander Marechal
I've
written a simple Python class for creating daemons on unix/linux
systems. It was pieced together for various other examples, mostly
corrections to various Python Cookbook
articles and a couple of examples posted to the Python mailing lists.
It has support for a pidfile to keep track of the process. I hope it's
useful to someone.
Below is the Daemon class. To use it, simply subclass it and implement the run() method.
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.

Usage: subclass the Daemon class and override the run() method
"""
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile

def daemonize(self):
"&q ......

python 创始人访谈录1:关于 django 和 ruby 收藏

python 创始人访谈录1:关于 django 和 ruby 收藏
主持人: Chris DiBona (Google 开源网站负责人) and Leo Laporte (Twit 网站创始人)
被采访人:Guido van Rossum (python 创始人)
Leo : Python 缺少一些本地的 gui 库吧,只有 tk 什么的, 你觉得这是不是一个问题呢?
Guido: 现在这越来越不成为一个问题了,因为越来越多的人使用 web 来做任何事情。
Leo :web 就是界面了
Guido: 但是的确也不解决什么问题,正如我说的:“ python 的 web 框架比语言中的关键字还多” , 我个人最喜欢的一个,也是我长期的选择框架是 django
Leo :我正打算问你 django 的事情, 最近有人写了一篇文章,我想是在 rails 网站上最先介绍的,它测试了,django , rails 和 perl 的 web 框架,django 的速度是最快的,远远超过其他。
Guido: 这很有趣,我没听说过这个。
C:你怎么测试一个 web 框架啊?
Leo :他们设置一些 web 测试应用程序,建立一系列的事务测试案例来测试事务操作, django 的速度相当的快,相当的快。 跟我们讲讲 django 吧
Guido:我是一个对 django 非常满意的用户,并在项目中使用了一些 django 。我将 django 称为“第二代&rdqu ......

python 创始人访谈录1:关于 django 和 ruby 收藏

python 创始人访谈录1:关于 django 和 ruby 收藏
主持人: Chris DiBona (Google 开源网站负责人) and Leo Laporte (Twit 网站创始人)
被采访人:Guido van Rossum (python 创始人)
Leo : Python 缺少一些本地的 gui 库吧,只有 tk 什么的, 你觉得这是不是一个问题呢?
Guido: 现在这越来越不成为一个问题了,因为越来越多的人使用 web 来做任何事情。
Leo :web 就是界面了
Guido: 但是的确也不解决什么问题,正如我说的:“ python 的 web 框架比语言中的关键字还多” , 我个人最喜欢的一个,也是我长期的选择框架是 django
Leo :我正打算问你 django 的事情, 最近有人写了一篇文章,我想是在 rails 网站上最先介绍的,它测试了,django , rails 和 perl 的 web 框架,django 的速度是最快的,远远超过其他。
Guido: 这很有趣,我没听说过这个。
C:你怎么测试一个 web 框架啊?
Leo :他们设置一些 web 测试应用程序,建立一系列的事务测试案例来测试事务操作, django 的速度相当的快,相当的快。 跟我们讲讲 django 吧
Guido:我是一个对 django 非常满意的用户,并在项目中使用了一些 django 。我将 django 称为“第二代&rdqu ......

应用python编写shell脚本

转载自
http://blog.163.com/skynjl/blog/static/603053922009127101558356/
 
 
今天同事叫我编写一个shell脚本。话说,虽然我受*nix的影响甚深,但是对于*nix 里随处可见的sh脚本却是讨厌之极。为什么讨厌呢?首先是因为sh脚本那莫名其妙的语法,感觉就像随写随扔的程序,完全没有任何美感可言。其次是sh脚本的处理能力还是比较弱的,在文本处理、XML处理还有网络编程方面,基本上都要借助于perl,awk等一堆程序。我对这些程序也是不大喜欢的,况且学习第三方软件总要时间,还不如都用python好了。
那,python可以做shell脚本吗? 首先介绍一个函数:
os.system(command)
这个函数可以调用shell运行命令行command并且返回它的返回值。试一下在 python的解释器里输入os.system(”ls -l”),就可以看到”ls”列出了当前目录下的文件。可以说,通过这个函数,python就拥有了shell的所有能力。呵呵。。不过,通常这条命令不需要用到。因为shell常用的那些命令在python中通常有对应而且同样简洁的写法。
shell中最常用的是ls命令,python对应的写法是:os.listdir(dirname),这个函数返回字符串列表,里面是所有的文件名,不过不包含&rdquo ......

Python模块学习

  Python标准模块中,有多个模块用于数据的压缩与解压缩,如zipfile,gzip, bz2等等。上次介绍了zipfile模块,今天就来讲讲zlib模块。 zlib.compress(string[, level]) zlib.decompress(string[, wbits[, bufsize]])   zlib.compress用于压缩流数据。参数string指定了要压缩的数据流,参数level指定了压缩的级别,它的取值范围是1到9。压缩速度与压缩率成反比,1表示压缩速度最快,而压缩率最低,而9则表示压缩速度最慢但压缩率最高。zlib.decompress用于解压数据。参数string指定了需要解压的数据,wbits和bufsize分别用于设置系统缓冲区大小(window buffer )与输出缓冲区大小(output buffer)。下面用一个例子来演示如何使用这两个方法: #coding=gbk
import zlib, urllib
fp = urllib.urlopen('http://localhost/default.html')
str = fp.read()
fp.close()
#---- 压缩数据流。
str1 = zlib.compress(str, zlib.Z_BEST_COMPRESSION)
str2 = zlib.decompress(str1)
print len(str)
print len(str1)
print len(str2) # ---- 结果
#5783
#5783  我们也可以使用Compress/Decompress对象来对数据进行压缩/解压缩。zlib.compressobj([level]) 与zlib.decom ......

Python3在ubuntu环境下的安装

       首先下载最新版本的Python,在这里我的版本是Python3.1.1。然后就是安装,切换到Python的文件目录下:
./configure
make
make test
sudo make install
      在这里可能会遇到几个问题,第一个是在./configure时,可能会出现C compiler cannot create executables,对于这个问题的解决,可以使用sudo apt-get install build-essential命令来解决。
      还有一个问题是在安装完成后,使用Python命令来测试安装是否成功时,如果以前预装了Python2.6,仍然会显示旧有的版本。原因在于安装时没有设置--prefit,默认安装在/usr/local目录,/usr/bin文件仍然连接到原有的Python版本。解决方案是:
sudo rm /usr/bin/python
sudo ln /usr/local/python*
/usr/bin/python即可。
......

[转] 最简单的使用UDP通信的Python Socket例子

来源:http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
客户端程序代码:
# Client program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
def_msg = "===Enter message to send to server===";
print "\n",def_msg
# Send messages
while (1):
data = raw_input('>> ')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."
# Close socket
UDPSock.close()
服务器端程序代码:
# Server program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
......
总记录数:695; 总页数:116; 每页6 条; 首页 上一页 [107] [108] [109] [110] [111] [112] [113] [114] 115 [116]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号