上一页 1 2 3 4 5 6 ··· 10 下一页
摘要: # Some strings for ctype-style character classification c风格字符串whitespace = ' \t\n\r\v\f' #空白字符 \t 制表符 \n换行lowercase = 'abcdefghijklmnopqrstuvwxyz'uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'letters = lowercase + uppercaseascii_lowercase = lowercaseascii_uppercase = uppercaseascii 阅读全文
posted @ 2013-07-18 14:08 践道者 阅读(567) 评论(0) 推荐(0) 编辑
摘要: def make_addr(addend): def addr(augend): return augend + addend return addrp = make_addr(23)q = make_addr(42)print p(10)print q(10) 阅读全文
posted @ 2013-07-18 11:36 践道者 阅读(216) 评论(0) 推荐(0) 编辑
摘要: import optparsedef parse_args(): usage = """ How to use parser options """ parser = optparse.OptionParser(usage) help = "The port to listen on." parser.add_option('--port', type='int', help=help) parser.add_option('--iface', default= 阅读全文
posted @ 2013-07-11 16:57 践道者 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 由于python没有接口概念,所以zope 提供了个第三方库开源使用,下面简单介绍zope.interface.implementer的使用直接看例子,下面例子是在twisted里摘录的接口IResolverSimpleclass IResolverSimple(Interface): def getHostByName(name, timeout = (1, 3, 11, 45)): """ Resolve the domain name C{name} into an IP address. """实现BlockingResolv 阅读全文
posted @ 2013-07-10 14:39 践道者 阅读(4435) 评论(0) 推荐(0) 编辑
摘要: 一个twisted进程只会有一个reactor反应器,下面我们来看看twisted是怎样实现这个单例反应器的,路径:twisted\internet\reactor.py主要代码如下:import sysdel sys.modules['twisted.internet.reactor'] #删除已经加载的reactor模块from twisted.internet import default #重新安装reactor模块,其实是加载twisted.internet.selectreactordefault.install() 进行安装这样就保证reactor只有一个实例具体 阅读全文
posted @ 2013-07-09 17:32 践道者 阅读(880) 评论(0) 推荐(0) 编辑
摘要: print会自动添加换行符其它的,没什么区别。有时候为了使用灵活,才会这么用。例如你想把print的内容写向一下log文件,你可以这么做stdout_bk = sys.stdout #备份一下标准输出sys.stdout = open("aa.log", "w") #标准输出重定向到一个文件这样子,print的内容就会全部输向xx.logflog=open("xx.log","w")print>>flog,"sth.toprint"建议用这种形式的重定向一是,所见即所得二是,不用备份 阅读全文
posted @ 2013-07-09 15:42 践道者 阅读(449) 评论(0) 推荐(0) 编辑
摘要: 迭代器lst = range(10) #生成一个枚举列表 从0-9itr = iter(lst) #生成一个迭代器itr.next() #访问迭代器方法遍历迭代器try: while True: val = itr.next() print valexcept StopIteration: pass注意:1、如果对list dict tuple 用for遍历,则for内部自动将之转换为迭代器2、enumerate给迭代器元素生成索引生成器生成器也是迭代器的一种,就是用了yield关键词def get_0_1_2(): yield 0 prin... 阅读全文
posted @ 2013-07-03 14:28 践道者 阅读(283) 评论(0) 推荐(0) 编辑
摘要: import calendar, SimpleXMLRPCServerclass Calendar: def getMonth(self, year, month): return calendar.month(year, month) def getYear(self, year): return calendar.calendar(year)calendar_object = Calendar()server = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost', 8888))server.regi... 阅读全文
posted @ 2013-06-27 11:03 践道者 阅读(463) 评论(0) 推荐(0) 编辑
摘要: from twisted.internet import reactorimport timedef printTime(): print "Current time is",time.strftime("%H:%M:%S")def stopReactor(): print "Stopping reactor" print "Current time is",time.strftime("%H:%M:%S") reactor.stop()reactor.callLater(1, printTim 阅读全文
posted @ 2013-06-26 12:00 践道者 阅读(508) 评论(0) 推荐(0) 编辑
摘要: #coding=utf8import ConfigParserconfig = ConfigParser.ConfigParser()config.readfp(open(raw_input("input file name:"), "rb"))print config.get("global", "ip") config.ini[global]ip = 192.168.1.100 ;ip地址port = 3306password = 123456 阅读全文
posted @ 2013-06-19 14:19 践道者 阅读(17460) 评论(0) 推荐(0) 编辑
摘要: 查看threading 有如下表达式_start_new_thread = thread.start_new_thread_allocate_lock = thread.allocate_lock_get_ident = thread.get_identThreadError = thread.errordel thread为什么要del thread,删除这个变量的目的是为什么?脚本运行完后应该会自动将变量清除。这样显式清除有什么特殊目的?如果不显式del会有什么后果?原来是目的是为了避免threading.thread的用法吧,为什么呢???因为有人喜欢dir(threading)然后看到 阅读全文
posted @ 2013-06-14 09:52 践道者 阅读(258) 评论(0) 推荐(0) 编辑
摘要: thread 对外提供的常用方法有:start_new_thread:创建新线程e.g. 看下面的示例更容易理解thread的线程机制:import timeimport threadfrom time import ctimedef timer(i, interval): while True: print "id:%s, time:%s \n"%(i, ctime()) time.sleep(interval)def test(): for i in range(5): thread.start_new_thread(timer, (i... 阅读全文
posted @ 2013-06-13 15:40 践道者 阅读(264) 评论(0) 推荐(0) 编辑
摘要: netstat -ant |grep "xxx.xxx.xxx.82" |wc -l 阅读全文
posted @ 2013-06-09 11:12 践道者 阅读(142) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2013-06-08 18:45 践道者 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 首先要有localesapt-get install locales接着用dpkg-reconfigure locales 进行配置 阅读全文
posted @ 2013-06-06 19:50 践道者 阅读(238) 评论(0) 推荐(0) 编辑
摘要: scp localeFile root@192.168.221.133:/usr/src/ 阅读全文
posted @ 2013-06-06 17:39 践道者 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1、新建用户insert into mysql.user(Host,User,Password)values("localhost","leon",password("123456"));2、为某用户授权访问某数据库grant all privileges on test.* to leon@localhost identified by '123456'; #所有权限grant select on test.* to leon@localhost identified by '123456'; #所有 阅读全文
posted @ 2013-06-06 15:15 践道者 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 1、查看表索引 show index from tb_name;2、增加索引 alter table tb_name add index index_name(column_name);3、删除索引 drop index index_name on tb_name;4、增加主键约束alter table tb_name add primary key PK_cid(cid);5、增加唯一约束ALTER TABLE `table_name` ADD UNIQUE (`column`) 阅读全文
posted @ 2013-06-06 14:46 践道者 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 1、创建数据库 create database if not exists db_name;2、指定字符集 create database if not exists db_name character set utf83、创建表、删除表 创建:create table tb_name (id int(4) not null primary key auto_increment, name char(20) not null); 删除:drop table tb_name;4、增加字段 alter table tb_name add column age tinyint(2);5、修改... 阅读全文
posted @ 2013-06-06 11:29 践道者 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 1、显示数据库 show databases;2、显示表 show tables;3、显示表结构 desc table_name;4、选择当前数据库 select database();5、查看表详细信息 show create table tb_name; 阅读全文
posted @ 2013-06-05 23:20 践道者 阅读(161) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 10 下一页