<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>代码工厂@Code Blocks Forge</title>
	<atom:link href="http://ide.cbforge.com/feed" rel="self" type="application/rss+xml" />
	<link>http://ide.cbforge.com</link>
	<description>-http://cbforge.com For Code::Blocks, CodeLite, C++ programming with wxWidgets...</description>
	<pubDate>Wed, 10 Mar 2010 10:24:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>在apache上面部署django应用</title>
		<link>http://ide.cbforge.com/programming/python-programming/299.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/299.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:24:01 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=299</guid>
		<description><![CDATA[在前面的文章中介绍了django的一些部署方式。这里介绍django在apache上面的部署方式。1.测试环境: mandriva 2009.0 + python2.5.22.安装mysql:urpmi MySQL MySQL-client3.mysql-server的配置:注释skip-networking这一句在/etc/my.cnf4.安装其它必要包:urpmi apache-mod_python urpmi python-django python-mysqlpython-django在urpm中已经集成可以直接安装，但是你也可以到django的官网去下载最新安装包。5.配置apache:
&#160;

mkdir /home/mycodecd /home/mycode/usr/bin/django-admin.py startproject mysitecp /etc/httpd/modules.d/16_mod_python.conf /etc/httpd/modules.d/16_mod_python.conf_origcat /dev/null &#62; /etc/httpd/modules.d/16_mod_python.confvi /etc/httpd/modules.d/16_mod_python.conf在16_mod_python.conf中输入:
LoadModule python_module&#160;&#160;&#160;&#160;&#160;&#160;&#160; extramodules/mod_python.so
&#60;Location &#8220;/mysite/&#8221;&#62;&#160;&#160;&#160; SetHandler python-program&#160;&#160;&#160; PythonHandler django.core.handlers.modpython&#160;&#160;&#160; SetEnv DJANGO_SETTINGS_MODULE mysite.settings&#160;&#160;&#160; PythonOption django.root /mysite&#160;&#160;&#160; PythonDebug On&#160;&#160;&#160; PythonPath &#8220;['/home/mycode/'] + sys.path&#8221;&#60;/Location&#62;
7.重启apache:service httpd restart8.查看http://localhost/mysite即可。9.查看80端口被占用:netstat &#160; -anvp &#160; lsof &#160; -i &#160; :80 &#160; 



Share and Enjoy:


	
	
	
	
	
	
	
	
	
	
	
	
	
	




Related posts:安装django环境py2exe,生成可执行文件.Django [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/242.html' rel='bookmark' title='Permanent Link: 安装django环境'>安装django环境</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/194.html' rel='bookmark' title='Permanent Link: py2exe,生成可执行文件.'>py2exe,生成可执行文件.</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/270.html' rel='bookmark' title='Permanent Link: Django at a glance&#8211;Django初窥'>Django at a glance&#8211;Django初窥</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/299.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python的lambda函数与排序</title>
		<link>http://ide.cbforge.com/programming/python-programming/297.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/297.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:22:21 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=297</guid>
		<description><![CDATA[前几天看到了一行求1000的阶乘的Python代码：
print&#160;&#160; reduce(lambda&#160;&#160; x,y:x*y,&#160;&#160; range(1,&#160;&#160; 1001)) 
一下子被python代码的精简与紧凑所折服，故对代码进行了简单的分析。
reduce与range都是Python的内置函数。
range（1，1001）表示生成1到1000的连续整数列表（List）。
&#160;

&#160;
reduce（functionA，iterableB），functionA为需要两个变量的函数，并返回一个值。iterableB为可迭代变量，如List等。reduce函数将B中的元素从左到右依次传入函数A中，再用函数A返回的结果替代传入的参数，反复执行，则可将B reduce成一个单值。在此，是将1到1000的连续整数列表传入lambda函数并用两个数的积替换列表中的数，实际的计算过程为：(&#8230;((1×2)×3)×4)×&#8230;×1000)，最后的结果即1000的阶乘。
下面来介绍一下lambda函数。
lambda函数是一种快速定义单行的最小函数，是从 Lisp 借用来的，可以用在任何需要函数的地方。下面的例子比较了传统的函数与lambda函数的定义方式：
1 &#62;&#62;&#62; def f(x,y):2 &#8230;&#160;&#160;&#160;&#160; return x*y3 &#8230;&#160;&#160;&#160;&#160; 4 &#62;&#62;&#62; f(2,3)5 66 &#62;&#62;&#62; g = lambda x,y: x*y7 &#62;&#62;&#62; g(2,3)8 6 
可以看到，两个函数得到的结果一样，而对于实现简单功能的函数来说，使用lambda函数来定义更加精简灵活，还可以直接把函数赋值给一个变量，用变量名来表示函数名。
其实lambda函数在很多时候都是不需要赋值给一个变量的（如前文中求阶乘的过程）。使用lambda函数还有一些注意事项：lambda 函数可以接收任意多个参数 (包括可选参数) 并且返回单个表达式的值。lambda 函数不能包含命令，包含的表达式不能超过一个。下面简单演示一下如何使用lambda函数实现自定义排序。 01 class People:02 &#160;&#160;&#160; age=003 &#160;&#160;&#160; gender=&#8217;male&#8217;04 05 &#160;&#160;&#160; def __init__(self, age, gender):&#160; 06 &#160;&#160;&#160;&#160;&#160;&#160;&#160; self.age = age&#160; 07 &#160;&#160;&#160;&#160;&#160;&#160;&#160; self.gender [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/204.html' rel='bookmark' title='Permanent Link: 序列、元组、列表、字典'>序列、元组、列表、字典</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/297.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python:什么是*args和**kwargs</title>
		<link>http://ide.cbforge.com/programming/python-programming/295.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/295.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:20:28 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=295</guid>
		<description><![CDATA[先来看个例子：
def foo(*args, **kwargs): print &#8216;args = &#8216;, args print &#8216;kwargs = &#8216;, kwargs print &#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8217; if __name__ == &#8216;__main__&#8217;: foo(1,2,3,4) foo(a=1,b=2,c=3) foo(1,2,3,4, a=1,b=2,c=3) foo(&#8217;a', 1, None, a=1, b=&#8217;2&#8242;, c=3)输出结果如下： 
&#160;

&#160;
args =&#160; (1, 2, 3, 4) kwargs =&#160; {} &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; args =&#160; () kwargs =&#160; {&#8217;a': 1, &#8216;c&#8217;: 3, &#8216;b&#8217;: 2} &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; args =&#160; (1, 2, [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/230.html' rel='bookmark' title='Permanent Link: Python: 什么是*args和**kwargs'>Python: 什么是*args和**kwargs</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/289.html' rel='bookmark' title='Permanent Link: Python CGI实现用户会话'>Python CGI实现用户会话</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/216.html' rel='bookmark' title='Permanent Link: Python 多线程 XML RPC的实现'>Python 多线程 XML RPC的实现</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/295.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python的map,filter,reduce函数</title>
		<link>http://ide.cbforge.com/programming/python-programming/293.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/293.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 10:19:13 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=293</guid>
		<description><![CDATA[map函数func作用于给定序列的每个元素，并用一个列表来提供返回值。map函数python实现代码：
def map(func,seq): &#160;&#160;&#160;&#160;mapped_seq = [] &#160;&#160;&#160;&#160;for eachItem in seq: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mapped_seq.append(func(eachItem)) &#160;&#160;&#160;&#160;return mapped_seq 
&#160;
&#160;

filter函数的功能相当于过滤器。调用一个布尔函数bool_func来迭代遍历每个seq中的元素；返回一个使bool_seq返回值为true的元素的序列。filter函数python代码实现：
def filter(bool_func,seq): &#160;&#160;&#160;&#160;filtered_seq = [] &#160;&#160;&#160;&#160;for eachItem in seq: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if bool_func(eachItem): &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;filtered_seq.append(eachItem) &#160;&#160;&#160;&#160;return filtered_seq 
reduce函数，func为二元函数，将func作用于seq序列的元素，每次携带一对（先前的结果以及下一个序列的元素），连续的将现有的结果和下一个值作用在获得的随后的结果上，最后减少我们的序列为一个单一的返回值。reduct函数python代码实现：
def reduce(bin_func,seq,initial=None): &#160;&#160;&#160;&#160;lseq = list(seq) &#160;&#160;&#160;&#160;if initial is None: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;res = lseq.pop(0) &#160;&#160;&#160;&#160;else: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;res = initial &#160;&#160;&#160;&#160;for eachItem in lseq: &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;res = bin_func(res,eachItem) &#160;&#160;&#160;&#160;return res 
下面是测试的代码
#coding:utf-8
def map_func(lis):&#160;&#160;&#160;&#160;return lis + [...]


No related posts.]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/293.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python随机数与随机字符串</title>
		<link>http://ide.cbforge.com/programming/python-programming/291.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/291.html#comments</comments>
		<pubDate>Mon, 11 Jan 2010 03:03:12 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=291</guid>
		<description><![CDATA[随机整数：&#62;&#62;&#62; import random&#62;&#62;&#62; random.randint(0,99)21
随机选取0到100间的偶数：&#62;&#62;&#62; import random&#62;&#62;&#62; random.randrange(0, 101, 2)42
随机浮点数：&#62;&#62;&#62; import random&#62;&#62;&#62; random.random() 0.85415370477785668&#62;&#62;&#62; random.uniform(1, 10)5.4221167969800881
&#160;

随机字符：&#62;&#62;&#62; import random&#62;&#62;&#62; random.choice(&#8217;abcdefg&#38;#%^*f&#8217;)&#8216;d&#8217;
多个字符中选取特定数量的字符：&#62;&#62;&#62; import randomrandom.sample(&#8217;abcdefghij&#8217;,3) ['a', 'd', 'b']
多个字符中选取特定数量的字符组成新字符串：&#62;&#62;&#62; import random&#62;&#62;&#62; import string&#62;&#62;&#62; string.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).replace(&#8221; &#8220;,&#8221;")&#8216;fih&#8217;
随机选取字符串：&#62;&#62;&#62; import random&#62;&#62;&#62; random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )&#8216;lemon&#8217;
洗牌：&#62;&#62;&#62; import random&#62;&#62;&#62; items = [1, 2, 3, 4, 5, 6]&#62;&#62;&#62; random.shuffle(items)&#62;&#62;&#62; items[3, 2, 5, 6, [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/204.html' rel='bookmark' title='Permanent Link: 序列、元组、列表、字典'>序列、元组、列表、字典</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/194.html' rel='bookmark' title='Permanent Link: py2exe,生成可执行文件.'>py2exe,生成可执行文件.</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/176.html' rel='bookmark' title='Permanent Link: 开始Python &#8212; Dictionary'>开始Python &#8212; Dictionary</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/291.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Python CGI实现用户会话</title>
		<link>http://ide.cbforge.com/programming/python-programming/289.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/289.html#comments</comments>
		<pubDate>Sun, 06 Dec 2009 06:30:19 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=289</guid>
		<description><![CDATA[众所周知，http协议是无状态的，也就是说客户端每次连接到服务器时，都是一个全新的状态，上一次访问服务器的状态无法在当次访问中维持，在B/S应用开发中，通常使用Cookie保存客户端状态，Cookies最典型的应用是判定注册用户是否已经登录网站，用户可能会得到提示，是否在下一次进入此网站时保留用户信息以便简化登录手续，这些都是
Cookies的功用。另一个重要应用场合是“购物车”之类处理。用户可能会在一段时间内在同一家网站的不同页面中选择不同的商品，这些信息都会写入
Cookies，以便在最后付款时提取信息。而后来的http会话(session）机制则是提供了另一种在服务器和客户端之间保持状态同步的方法，于采用服务器端保持状态的方案在客户端也需要保存一个标识，所以session机制可能需要借助于cookie机制来达到保存标识的目的。PHP、ASP都提供了较方面的方法创建和管理Session，Python的cgi模块却没有，在作一些简单的应用时，可以通过一些简单的方法手动实现Session的创建和管理。具体步骤如下：
1,在用户登录时，随机生成会话标识，同时保存在服务器端和客户端Cookie中;2,用户登录完成后的每次访问，检查客户端Cookie中的会话标识，与服务器中的会话标识比较，以确定用户是否已登录;3,用户退出登录后，清除客户端Cookie中的会话标识及服务器端的会话标识，退出会话。
下面是登录页面的部份代码：
#!/usr/bin/python# -*- coding: utf8 -*-
import sys,os,cgi,MySQLdb,random,sha,Cookiefrom option import *
def check_login(username,password):&#160;&#160;&#160; global data_server,server_username,server_password,database_name&#160;&#160;&#160; try:&#160;&#160;&#160; &#160;&#160;&#160; conn=MySQLdb.connect(host=data_server,user=server_username,passwd=server_password,db=database_name)&#160;&#160;&#160; &#160;&#160;&#160; conn.set_character_set(&#8217;UTF8&#8242;)&#160;&#160;&#160; except Exception,e:&#160;&#160;&#160; &#160;&#160;&#160; print e&#160;&#160;&#160; &#160;&#160;&#160; sys.exit()&#160;&#160;&#160; cursor=conn.cursor()&#160;&#160;&#160; sql=&#8217;SELECT id FROM user_man WHERE login_name LIKE &#34;%s&#34; AND password LIKE &#34;%s&#34;&#8217; %(username,password)&#160;&#160;&#160; cursor.execute(sql)&#160;&#160;&#160; ss=cursor.fetchall()&#160;&#160;&#160; if ss:&#160;&#160;&#160; &#160;&#160;&#160; userid=ss[0][0]&#160;&#160;&#160; &#160;&#160;&#160; cursor.close()&#160;&#160;&#160; &#160;&#160;&#160; save_session(userid)&#160;&#160;&#160; &#160;&#160;&#160; return 1&#160;&#160;&#160; else:&#160;&#160;&#160; &#160;&#160;&#160; cursor.close()&#160;&#160;&#160; &#160;&#160;&#160; [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/open-source/167.html' rel='bookmark' title='Permanent Link: Python Programming &ndash; Sqlite for data persistence'>Python Programming &ndash; Sqlite for data persistence</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/222.html' rel='bookmark' title='Permanent Link: Python Daemon(守护进程）'>Python Daemon(守护进程）</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/230.html' rel='bookmark' title='Permanent Link: Python: 什么是*args和**kwargs'>Python: 什么是*args和**kwargs</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/289.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>python中的类型判定</title>
		<link>http://ide.cbforge.com/programming/python-programming/287.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/287.html#comments</comments>
		<pubDate>Tue, 01 Dec 2009 09:34:21 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=287</guid>
		<description><![CDATA[python中的类型判定有如下几种方法：（1）&#62;&#62;&#62;print type(1)==intTrue（2）isinstance(1,(int,str))True注意，此处第二个参数可以是个tuple，只要第一个参数是其中任何一个类型时，就返回True（3）import types&#62;&#62;&#62; int&#60;type &#8216;int&#8217;&#62;&#62;&#62;&#62; IntType&#60;type &#8216;int&#8217;&#62;&#62;&#62;&#62; print int is IntTypeTrue可知，IntType和int是同一类型对象，具有同一object id。



Share and Enjoy:


	
	
	
	
	
	
	
	
	
	
	
	
	
	




Related posts:Built-in FunctionsLinux下Python网络编程框架-Twisted安装手记


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/252.html' rel='bookmark' title='Permanent Link: Built-in Functions'>Built-in Functions</a></li><li><a href='http://ide.cbforge.com/open-source/206.html' rel='bookmark' title='Permanent Link: Linux下Python网络编程框架-Twisted安装手记'>Linux下Python网络编程框架-Twisted安装手记</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/287.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>python元类的一些新认识</title>
		<link>http://ide.cbforge.com/programming/python-programming/285.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/285.html#comments</comments>
		<pubDate>Tue, 01 Dec 2009 09:33:23 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=285</guid>
		<description><![CDATA[如果定义了一个类A和他的元类B，如果只实例化B，那么A也会被实例化。代码如下：
#coding:utf-8class FA(type):&#160;&#160;&#160;&#160;def __new__(cls, name, base, attr):&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print base&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print attr&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print &#8220;it is in fa&#8217;s new&#8221;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;new_obj = super(FA, cls).__new__(cls, name, base, attr)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return new_obj

class FB(object):&#160;&#160;&#160;&#160;def __init__(self):&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print &#8220;it is in FB&#8217;s init&#8221;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self.group = &#8216;china&#8217;
class FC(FB):&#160;&#160;&#160;&#160;__metaclass__ = FA&#160;&#160;&#160;&#160;def __init__(self):&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print &#8220;it is in FC&#8217;s init&#8221;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self.number = 3&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;#fc = FC() print &#8220;=&#8221; * 20 fa = FA(&#8217;fa_name&#8217;, (), {&#8217;age&#8217;:22}) 运行结果如下：C:\&#62;python test.pyFC(&#60;class &#8216;__main__.FB&#8217;&#62;,){&#8217;__module__&#8217;: [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/232.html' rel='bookmark' title='Permanent Link: django中ModelBase的属性'>django中ModelBase的属性</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/268.html' rel='bookmark' title='Permanent Link: Python线程编程的两种方式'>Python线程编程的两种方式</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/220.html' rel='bookmark' title='Permanent Link: python3.0与2.x之间的区别'>python3.0与2.x之间的区别</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/285.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>XML-RPC in Python简介</title>
		<link>http://ide.cbforge.com/programming/python-programming/283.html</link>
		<comments>http://ide.cbforge.com/programming/python-programming/283.html#comments</comments>
		<pubDate>Sat, 28 Nov 2009 03:30:39 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=283</guid>
		<description><![CDATA[心得：本地 &#8212;&#8212;&#8212;&#8212;- 远程调用方法就包括了：方法名、参数、返回值这些如果在本地就可以直接传入调用处理。如果是远程的话步骤如下：第一、将参数之类的信息转换成XML格式的数据流第二、传入到服务器端解析之后进行执行返回结果封装成XML格式数据包第三、客户端接收到这些XML的数据包同样进行解析得到想要的数据格式。用网络传递的话，和系统和语言都没有关系了这样的话我就可以在本地写一个JAVA的代码去调用一个NET的服务接口了。通过一些语言的内库直接实现这种XML与文本流的互换。我们主要关心的就是如何写好服务器端的函数逻辑了！

import xmlrpclibserver = xmlrpclib.Server(&#8221;http://www.example.com/RPC2&#8220;)&#160;&#160; #这个就相当于是一个对象了。能够通过这个对象去调用它的方法result = server.calculate_a_plus_b(5,8) 
XML-RPC的不足：毕竟要经过&#8221;函数调用&#8221;-&#62;XML转换过程，运行时要付出时间的代价。但是开发时间有时候比运行时效率更重要。 (要将文本内容转换成XML一种类型的所以效率上不是很理想的！)
其它类似XML-RPC的协议：SOAP：W3C提出的协议，功能比XML-RPC强大，但是太复杂。 &#160;
哦原来它俩是一家的呀。编写WEB服务接口就要用SOAP了！
将数据定义为xml格式，通过http协议进行远程传输。（服务端与客户端都是这样处理的！）
需要掌握的第一：服务器端如何编写第二、客户端如何编写可能的方法调用示例如下：A list of possible usage patterns follows:
1. Install functions:
server = SimpleXMLRPCServer((&#8221;localhost&#8221;, 8000))server.register_function(pow)server.register_function(lambda x,y: x+y, &#8216;add&#8217;)server.serve_forever()
2. Install an instance:
class MyFuncs:&#160;&#160;&#160; def __init__(self):&#160;&#160;&#160;&#160;&#160;&#160;&#160; # make all of the string functions available through&#160;&#160;&#160;&#160;&#160;&#160;&#160; # string.func_name&#160;&#160;&#160;&#160;&#160;&#160;&#160; import string&#160;&#160;&#160;&#160;&#160;&#160;&#160; self.string = string&#160;&#160;&#160; def _listMethods(self):&#160;&#160;&#160;&#160;&#160;&#160;&#160; # implement this method so [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/programming/python-programming/216.html' rel='bookmark' title='Permanent Link: Python 多线程 XML RPC的实现'>Python 多线程 XML RPC的实现</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/242.html' rel='bookmark' title='Permanent Link: 安装django环境'>安装django环境</a></li><li><a href='http://ide.cbforge.com/programming/python-programming/228.html' rel='bookmark' title='Permanent Link: python通过SMTPLIB发送邮件'>python通过SMTPLIB发送邮件</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/python-programming/283.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Singleton模式</title>
		<link>http://ide.cbforge.com/programming/c-programming/281.html</link>
		<comments>http://ide.cbforge.com/programming/c-programming/281.html#comments</comments>
		<pubDate>Sat, 28 Nov 2009 03:04:25 +0000</pubDate>
		<dc:creator>minitia</dc:creator>
		
		<category><![CDATA[C++ Programming]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ide.cbforge.com/?p=281</guid>
		<description><![CDATA[一、在GOF著作中对Singleton模式的实现方式如下：
/*解一*/&#160; &#160;// Header file Singleton.h class&#160;Singleton&#160; &#160;{&#160; &#160;public:&#160; &#160; static&#160;Singleton&#160;*Instance(){&#160;&#160;&#160;&#160;&#160;&#160; //1&#160; &#160; if(&#160;!m_pInstatnce)&#160;//2 m_pInstance&#160;=&#160;new&#160;Singleton;//3&#160; &#160; return&#160;m_pInstance;&#160;//4&#160; &#160; }&#160; &#160;void DoSomething();private:&#160; &#160; static&#160;Singleton&#160;*m_pInstatnce=NULL; //5&#160; &#160;private:&#160; &#160; Singleton(); //6&#160; &#160; Singleton(const&#160;Singleton&#38;); //7&#160; &#160; Singleton&#38;&#160;operator=(const&#160;Singleton&#38;); //8&#160; &#160; ~Singleton();&#160; //9&#160; &#160;}&#160;&#160;&#160;&#160;&#160;

// Implementation file Singleton.cpp Singleton* Singleton::m_pInstance = 0;
客户代码现在可以这样使用Singleton：
1 Singleton &#38;s = Singleton::Instance();2 s.DoSomething();在上面的解决方案中，我们只在需要调用时，才产生一个Singleton的对象。这样带来的好处是，如果该对象产生带来的结果很昂贵，但不经常用到时，是一种非常好的策略。但如果该Instance被频繁调用，就有人觉得Instance()中的判断降低了效率。
二、Meyers Singleton我们如何解决这个问题呢，实际上很简单。一种非常优雅的做法由Scott Meyers最先提出，故也称为Meyers Singleton。它依赖编译器的神奇技巧,即函数内的static对象只在该函数第一次执行时才初始化（请注意不是static常量）。
/*解二*/&#160;&#160; // Header file [...]


Related posts:<ol><li><a href='http://ide.cbforge.com/ide/codelite/105.html' rel='bookmark' title='Permanent Link: Codelite代码分析之 Singleton Pattern Template实现及应用'>Codelite代码分析之 Singleton Pattern Template实现及应用</a></li><li><a href='http://ide.cbforge.com/programming/c-programming/246.html' rel='bookmark' title='Permanent Link: AVL树Source Code'>AVL树Source Code</a></li></ol>]]></description>
		<wfw:commentRss>http://ide.cbforge.com/programming/c-programming/281.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
