Memcached
是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能。
网上有很多讲到Memcached For Linux的安装教程,但是Memcached For Win32 and Python的就甚少,偶尔google找到一篇
比较相近的英文教程,觉得很不错就打算翻译下来,并且写一个Hello World的memcached实例。
安装部分来自原文
1.下载memcached 1.2.1 for Win32
.
2.把memcached-1.2.1-win32.zip解包到你想要的路径下
(如:C:\memcached-1.2.1-win32)
3.打开命令行(在开始菜单中的"运行",输入"cmd"),使用以下的命令安装:
C:\memcached-1.2.1-win32\memcached.exe -d install
安装完成之后,再执行以下命令来启动memcached:
C:\memcached-1.2.1-win32\memcached.exe -d start
这样memcached会使用默认的端口(11211)来启动,启动成功的话,你可以在任务管理器中看到memcached.exe
4.为了和memcached通信,你需要安装一个memcached客户端
,来对memcached做“增删改”操作。memcached有很多个客户
端程序可以使用,对应于各种语言,有各种语言� ......
代码+结果,不做解释
当然,对于python没有virtual function一说,估计当作对比一个例子看看吧。
#include <iostream>
using namespace std;
class base
{
public:
virtual void foo() { cout << "base" << endl; }
base() { foo() ;}
};
class derive: public base
{
public:
derive() { foo(); }
virtual void foo() { cout << "derive" << endl; }
};
int main()
{
derive d;
return 0;
}
结果:
base
derive
class base(object):
def __init__( self ):
self.foo()
def foo( self ):
print "base"
class derive( base ):
def __init__( self ):
super( derive , self ).__init__()
self.foo()
def foo( self ):
print "derive"
d = derive()
结果:
derive
derive ......
代码+结果,不做解释
当然,对于python没有virtual function一说,估计当作对比一个例子看看吧。
#include <iostream>
using namespace std;
class base
{
public:
virtual void foo() { cout << "base" << endl; }
base() { foo() ;}
};
class derive: public base
{
public:
derive() { foo(); }
virtual void foo() { cout << "derive" << endl; }
};
int main()
{
derive d;
return 0;
}
结果:
base
derive
class base(object):
def __init__( self ):
self.foo()
def foo( self ):
print "base"
class derive( base ):
def __init__( self ):
super( derive , self ).__init__()
self.foo()
def foo( self ):
print "derive"
d = derive()
结果:
derive
derive ......
#coding=utf-8
from math import sqrt,cos,sin
import Image, ImageDraw
class SpireShape(object):
def __init__(self, draw):
self.draw = draw
self.line_width = 1
self.line_color = (0,0,0)
self.current_point = (0, 0)
def setPoints(self,points):
self.points = points
def setLineWidth(self,line_width):
self.line_width = line_width
def setLineColor(self,line_color):
self.line_color = line_color
def moveto(self, p):
self.current_point = p
def lineto(self, p):
......
【windows+python3.1.2】
发布python应用程序是个很麻烦的事,因为<1>无法编译原生code<2>每个版本的字节码不同<3>如果直接上源码会损害自己的利益——等等
方法1——手动打包
怎么打包呢?一个python文件夹要二十多MB啊!
yes!我们就要清理无用的东西!
先写一个win.py文件:
x = int(input("please a number: "))
print("your number is:",x)
再写run.bat:
@python -m py_compile win.py
@python win.pyc
@pause
然后把python文件夹里的文件全部复制到win和run的目录下。
现在开始精简——
1.先搜索所有的.txt,删除
2.删除Doc目录(你认为用户会去看python的文档吗?)
3.删除Tools目录
现在开始判断,用到tcl没?用到额外的库没?用到unicode没?用到ctypes没?然后进入各个目录进行删除额外的文件。因为我们的win.py什么都没有用到,所以删除除了python[.exe]外的所有东西,搞定!运行run.bat照样运行。
然后——打包所需的库,再按相同的办法去除无用的东西(我测试时用^x^v来测试,比较简便,你认为什么方法比较方便?)
方法2——用户操作
这� ......
There should be one—--and preferably only one –--obvious way to do it.
----摘自The Zen of Python, by Time Peters
一些往事
在正式进入Decorator话题之前,请允许我讲一� ......
这两天在学习python语言,也学着写了个通讯簿,练习入门下!
功能包括以下:
1、增加一条记录
2、删除一条记录
3、修改一条记录
4、查询一条记录
5、显示整个通讯簿
6、帮助提示
7、版本显示
8、退出等
首先建立一个Person类,即Person.py文件,用来保存联系人记录:
class Person:
def __init__(self, name, email, phone):
self.name = name
self.email = email
self.phone = phone
接下来是个addressBook.py文件,用以实现上面提到的功能,这里用了存储器,将对象保存在文件中来实现数据存储。
import cPickle as p
from Person import Person
filename = 'addressBook.data'
while True:
order = raw_input('/////////////////////////////////////\nEnter your order:')
#add
if order == 'add':
addName = raw_input('Enter name:')
f = file(filename)
dic = p.load(f)
if dic.has_key(addName) == False:
dic[addName] = Person(addName, raw_input('Enter email:'), raw_input('Enter phone:'))
f = file(filename, 'w')
......